-
-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(postgraphql) add extendedErrors option
- Loading branch information
Showing
6 changed files
with
57 additions
and
2 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,43 @@ | ||
import { GraphQLError } from 'graphql/error' | ||
|
||
/** | ||
* Given a GraphQLError, format it according to the rules described by the | ||
* Response Format, Errors section of the GraphQL Specification, plus a few | ||
* additional fields relevant to postgres errors, including HINT, DETAIL, | ||
* and ERRCODE. | ||
*/ | ||
export function extendedFormatError(error: GraphQLError, fields: Array<String>): GraphQLFormattedErrorExtended { | ||
if (!error) { | ||
throw new Error('Received null or undefined error.') | ||
} | ||
const originalError = error.originalError as GraphQLErrorExtended | ||
fields = fields.map(field => field.toLowerCase()) | ||
return { | ||
message: error.message, | ||
locations: error.locations, | ||
path: error.path, | ||
hint: originalError && fields.indexOf('hint') > -1 ? originalError.hint : undefined, | ||
detail: originalError && fields.indexOf('detail') > -1 ? originalError.detail : undefined, | ||
errcode: originalError && fields.indexOf('errcode') > -1 ? originalError.code : undefined, | ||
} | ||
} | ||
|
||
export type GraphQLFormattedErrorExtended = { | ||
message: string, | ||
locations: Array<GraphQLErrorLocation> | void, | ||
path: Array<string | number> | void, | ||
hint: string | void, | ||
detail: string | void, | ||
errcode: string | void, | ||
} | ||
|
||
export type GraphQLErrorLocation = { | ||
line: number, | ||
column: number, | ||
} | ||
|
||
export type GraphQLErrorExtended = GraphQLError & { | ||
hint: string, | ||
detail: string, | ||
code: string, | ||
} |
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