Skip to content

Commit

Permalink
Register logger middleware before errors middleware
Browse files Browse the repository at this point in the history
In the examples and project templates the "errors" middleware which turn
thrown errors into HTTP responses is registered before the "logger"
middleware. This causes any errors thrown in controllers to pierce
through the logger middleware resulting in these requests not being
logged.

Eg. when a controller throws a ValidationError the resulting HTTP 400
request is not logged at all.

Change the order of middleware registration so that the logger is
'above' the errors middleware and has a chance to log *all* requests.
  • Loading branch information
goodhoko committed Nov 8, 2023
1 parent 22ffc8b commit 92bb176
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/getstarted/config/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const responseHandlers = require('./src/response-handlers');

module.exports = [
'strapi::logger',
'strapi::errors',
'strapi::security',
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
Expand Down
2 changes: 1 addition & 1 deletion examples/kitchensink-ts/config/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default [
'strapi::logger',
'strapi::errors',
'strapi::security',
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { resolveMiddlewares } from './middleware';
type MiddlewareConfig = (string | { name?: string; resolve?: string; config?: unknown })[];

const defaultConfig = [
'strapi::logger',
'strapi::errors',
'strapi::security',
'strapi::cors',
'strapi::poweredBy',
'strapi::session',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::favicon',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = [
'strapi::logger',
'strapi::errors',
'strapi::security',
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default [
'strapi::logger',
'strapi::errors',
'strapi::security',
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
Expand Down

0 comments on commit 92bb176

Please sign in to comment.