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

Commit f089244

Browse files
author
Tomasz Kostuch
authored
Merge pull request #431 from gibkigonzo/bugfix/disable-showing-stack
disable showing stack for invalid requests
2 parents 4bde19c + 270b520 commit f089244

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- Add correct paths for production build - @cewald (#407)
2626
- Fix MSI default stock id value
2727
- Add outputFormatter to response from cache - @gibkigonzo (#428)
28+
- disable showing stack for invalid requests - @gibkigonzo (#431)
2829

2930

3031
## [1.11.1] - 2020.03.17

config/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"availableCacheTags": ["P", "C", "T", "A", "product", "category", "attribute", "taxrule"],
1010
"invalidateCacheKey": "aeSu7aip",
1111
"invalidateCacheForwarding": false,
12-
"invalidateCacheForwardUrl": "http://localhost:3000/invalidate?key=aeSu7aip&tag="
12+
"invalidateCacheForwardUrl": "http://localhost:3000/invalidate?key=aeSu7aip&tag=",
13+
"showErrorStack": false
1314
},
1415
"orders": {
1516
"useServerQueue": false

src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,18 @@ app.use('/graphql', graphqlExpress(req => ({
7171

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

74+
app.use((err, req, res, next) => {
75+
const { statusCode, message = '', stack = '' } = err;
76+
const stackTrace = stack
77+
.split(/\r?\n/)
78+
.map(string => string.trim())
79+
.filter(string => string !== '')
80+
81+
res.status(statusCode).json({
82+
code: statusCode,
83+
result: message,
84+
...(config.get('server.showErrorStack') ? { stack: stackTrace } : {})
85+
});
86+
});
87+
7488
export default app;

0 commit comments

Comments
 (0)