Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Commit

Permalink
disable showing stack for invalid requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkostuch committed Apr 9, 2020
1 parent 42df865 commit 965247f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"availableCacheTags": ["P", "C", "T", "A", "product", "category", "attribute", "taxrule"],
"invalidateCacheKey": "aeSu7aip",
"invalidateCacheForwarding": false,
"invalidateCacheForwardUrl": "http://localhost:3000/invalidate?key=aeSu7aip&tag="
"invalidateCacheForwardUrl": "http://localhost:3000/invalidate?key=aeSu7aip&tag=",
"showErrorStack": false
},
"orders": {
"useServerQueue": false
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,15 @@ app.use('/graphql', graphqlExpress(req => ({

app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));

app.use((err, req, res, next) => {
const { statusCode, message, stack } = err;
res.status(statusCode).json({
code: statusCode,
result: config.get('server.showErrorStack') ? `
message: ${message};
stack: ${stack}
` : message
});
});

export default app;

3 comments on commit 965247f

@simonmaass
Copy link

@simonmaass simonmaass commented on 965247f Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gibkigonzo
after this commit I get:

2020-04-11 16:47:29: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
16:47:29 0|api | at ServerResponse.setHeader (_http_outgoing.js:470:11)
16:47:29 0|api | at ServerResponse.header (/var/www/node_modules/express/lib/response.js:771:10)
16:47:29 0|api | at ServerResponse.send (/var/www/node_modules/express/lib/response.js:170:12)
16:47:29 0|api | at ServerResponse.json (/var/www/node_modules/express/lib/response.js:267:15)
16:47:29 0|api | at app.use (/var/www/src/index.ts:97:26)
16:47:29 0|api | at Layer.handle_error (/var/www/node_modules/express/lib/router/layer.js:71:5)
16:47:29 0|api | at trim_prefix (/var/www/node_modules/express/lib/router/index.js:315:13)
16:47:29 0|api | at /var/www/node_modules/express/lib/router/index.js:284:7
16:47:29 0|api | at Function.process_params (/var/www/node_modules/express/lib/router/index.js:335:12)
16:47:29 0|api | at next (/var/www/node_modules/express/lib/router/index.js:275:10)

@simonmaass
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error

@gibkigonzo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change must be added at the end of the app initialization, because it needs to match only invalid routes. You have something in line 97 (16:47:29 0|api | at app.use (/var/www/src/index.ts:97:26)). So add this after all others app.use

Please sign in to comment.