Skip to content

Commit ecd605b

Browse files
authored
Should not GraphQL error extensions when it's wrapping an internal server error (#4116)
* Revert "Inherit GraphQL error extensions when it's wrapping an internal server error (#4093)" This reverts commit 5f75a42. * test * no leak internals * changeset
1 parent 580ad9d commit ecd605b

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

.changeset/loose-ideas-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-yoga': patch
3+
---
4+
5+
Does not GraphQL error extensions when it's wrapping an internal server error

packages/graphql-yoga/__tests__/error-masking.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,11 @@ describe('error masking', () => {
803803
});
804804
});
805805

806-
it('should inherit the extensions of a graphql error with original error', async () => {
806+
// extensions may contain internal data and we dont want to leak it
807+
it('should not inherit the extensions of a graphql error with original error', async () => {
807808
const wrappedError = createGraphQLError('I like tortoises', {
808809
extensions: {
809-
code: 'SOME_ERROR', // overwriting the INTERNAL_SERVER_ERROR code
810+
code: 'SOME_ERROR', // should not overwrite the INTERNAL_SERVER_ERROR code
810811
'x-hi': 'there',
811812
},
812813
originalError: new Error('I like turtles'),
@@ -841,8 +842,7 @@ describe('error masking', () => {
841842
"errors": [
842843
{
843844
"extensions": {
844-
"code": "SOME_ERROR",
845-
"x-hi": "there",
845+
"code": "INTERNAL_SERVER_ERROR",
846846
},
847847
"locations": [
848848
{

packages/graphql-yoga/src/utils/mask-error.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ export const maskError: MaskError = (
4242
if (error.extensions?.['http']) {
4343
errorExtensions['http'] = error.extensions['http'];
4444
}
45-
for (const key in error.extensions) {
46-
// this will be overwriting our extensions, this should be expected
47-
errorExtensions[key] = error.extensions[key];
48-
}
4945
} else if (isDev) {
5046
errorExtensions['originalError'] = serializeError(error);
5147
}

0 commit comments

Comments
 (0)