-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make errors configurable to handle stacktraces
- Loading branch information
Showing
24 changed files
with
817 additions
and
639 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@keystone-next/keystone': minor | ||
'@keystone-next/types': minor | ||
--- | ||
|
||
Add a `config.graphql.debug` option, which can be used to control with debug information such as stack traces are include in the errors returned by the GraphQL API. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
import { ApolloError } from 'apollo-server-errors'; | ||
|
||
export const accessDeniedError = () => new ApolloError('You do not have access to this resource'); | ||
|
||
export const validationFailureError = (messages: string[]) => { | ||
const s = messages.map(m => ` - ${m}`).join('\n'); | ||
return new ApolloError(`You provided invalid data for this operation.\n${s}`); | ||
}; | ||
|
||
export const extensionError = (extension: string, things: { error: Error; tag: string }[]) => { | ||
const s = things.map(t => ` - ${t.tag}: ${t.error.message}`).join('\n'); | ||
return new ApolloError( | ||
`An error occured while running "${extension}".\n${s}`, | ||
'INTERNAL_SERVER_ERROR', | ||
// Make the original stack traces available in non-production modes. | ||
// TODO: We need to have a way to make these stack traces available | ||
// for logging in production mode. | ||
process.env.NODE_ENV !== 'production' | ||
? { errors: things.map(t => ({ stacktrace: t.error.stack, message: t.error.message })) } | ||
: undefined | ||
); | ||
export type KeystoneErrors = { | ||
accessDeniedError: any; | ||
validationFailureError: any; | ||
extensionError: any; | ||
limitsExceededError: any; | ||
}; | ||
|
||
// FIXME: In an upcoming PR we will use these args to construct a better | ||
// error message, so leaving the, here for now. - TL | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const limitsExceededError = (args: { type: string; limit: number; list: string }) => | ||
new ApolloError('Your request exceeded server limits'); | ||
export const graphQlErrors = (debug: boolean | undefined): KeystoneErrors => ({ | ||
accessDeniedError: () => new ApolloError('You do not have access to this resource'), | ||
validationFailureError: (messages: string[]) => { | ||
const s = messages.map(m => ` - ${m}`).join('\n'); | ||
return new ApolloError(`You provided invalid data for this operation.\n${s}`); | ||
}, | ||
extensionError: (extension: string, things: { error: Error; tag: string }[]) => { | ||
const s = things.map(t => ` - ${t.tag}: ${t.error.message}`).join('\n'); | ||
return new ApolloError( | ||
`An error occured while running "${extension}".\n${s}`, | ||
'INTERNAL_SERVER_ERROR', | ||
// Make the original stack traces available in non-production modes. | ||
(debug === undefined ? process.env.NODE_ENV !== 'production' : debug) | ||
? { debug: things.map(t => ({ stacktrace: t.error.stack, message: t.error.message })) } | ||
: undefined | ||
); | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
limitsExceededError: (args: { type: string; limit: number; list: string }) => | ||
new ApolloError('Your request exceeded server limits'), | ||
}); |
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.