-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Errors Lifecycle: user extensions > engine reporting > formatError (#…
…1272) * enable willSendResponse to return a modified response * add formatError as an extension that wraps engine reporting * ensure that formatError once on every error path * move old formatError express tests into integration suite * add error lifecycle with minimal engine reporting check * increase granularity of formatError test * return 400 error for GraphQL error created by context * add check for internal server error for errors thrown in context * comment about context error status code
- Loading branch information
Showing
10 changed files
with
416 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { GraphQLExtension, GraphQLResponse } from 'graphql-extensions'; | ||
import { formatApolloErrors } from 'apollo-server-errors'; | ||
|
||
export class FormatErrorExtension extends GraphQLExtension { | ||
private formatError: Function; | ||
private debug: boolean; | ||
|
||
public constructor(formatError: Function, debug: boolean = false) { | ||
super(); | ||
this.formatError = formatError; | ||
this.debug = debug; | ||
} | ||
|
||
public willSendResponse(o: { | ||
graphqlResponse: GraphQLResponse; | ||
}): void | { graphqlResponse: GraphQLResponse } { | ||
if (o.graphqlResponse.errors) { | ||
return { | ||
graphqlResponse: { | ||
...o.graphqlResponse, | ||
errors: formatApolloErrors(o.graphqlResponse.errors, { | ||
formatter: this.formatError, | ||
debug: this.debug, | ||
}), | ||
}, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.