diff --git a/CHANGELOG.md b/CHANGELOG.md index 42b249b7..3425c7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add correct paths for production build - @cewald (#407) - Fix MSI default stock id value - Add outputFormatter to response from cache - @gibkigonzo (#428) +- disable showing stack for invalid requests - @gibkigonzo (#431) ## [1.11.1] - 2020.03.17 diff --git a/config/default.json b/config/default.json index d9fe9def..9906eaf9 100644 --- a/config/default.json +++ b/config/default.json @@ -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 diff --git a/src/index.ts b/src/index.ts index 313a84af..42c961d8 100755 --- a/src/index.ts +++ b/src/index.ts @@ -71,4 +71,18 @@ app.use('/graphql', graphqlExpress(req => ({ app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' })); +app.use((err, req, res, next) => { + const { statusCode, message = '', stack = '' } = err; + const stackTrace = stack + .split(/\r?\n/) + .map(string => string.trim()) + .filter(string => string !== '') + + res.status(statusCode).json({ + code: statusCode, + result: message, + ...(config.get('server.showErrorStack') ? { stack: stackTrace } : {}) + }); +}); + export default app;