Skip to content

Commit

Permalink
Do not set it 500 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jul 30, 2022
1 parent 784420a commit 079c14e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion packages/graphql-yoga/__tests__/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ describe('Context error', () => {
"data": null,
"errors": Array [
Object {
"extensions": Object {},
"message": "Unexpected error.",
},
],
Expand Down
9 changes: 7 additions & 2 deletions packages/graphql-yoga/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export class YogaServer<
return response
} catch (error: unknown) {
const finalResponseInit = {
status: 200,
status: 0,
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -551,7 +551,8 @@ export class YogaServer<
if (error.extensions?.http) {
if (
error.extensions.http.status &&
error.extensions?.http.status > finalResponseInit.status
(!finalResponseInit.status ||
error.extensions.http.status > finalResponseInit.status)
) {
finalResponseInit.status = error.extensions.http.status
}
Expand All @@ -566,6 +567,10 @@ export class YogaServer<
}
}

if (!finalResponseInit.status) {
finalResponseInit.status = 500
}

const payload: ExecutionResult = {
data: null,
errors,
Expand Down
8 changes: 1 addition & 7 deletions packages/graphql-yoga/src/utils/yogaDefaultFormatError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,5 @@ export const yogaDefaultFormatError: FormatErrorHandler = (
}
return err
}
return createGraphQLError(message, {
extensions: {
http: {
status: 500,
},
},
})
return createGraphQLError(message)
}

0 comments on commit 079c14e

Please sign in to comment.