-
-
Notifications
You must be signed in to change notification settings - Fork 620
added handleErrors option #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d26c992
added handleErrors option
pyramation c930f3c
error -> errors
pyramation 321f28d
added res.headersSent check
pyramation b7b544a
lint
pyramation 1c908c8
lint
pyramation edeeada
added 2 tests
pyramation 2f7c70b
lint
pyramation fb4472c
Make requested changes by @benjie
lifeiscontent 724f8b7
Throw error if handleErrors is used with other types of error handling
lifeiscontent 5857f06
Make requested changes
lifeiscontent 96979f1
Lint fixes
lifeiscontent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ npm-debug.log* | |
| build/ | ||
| TODO.md | ||
| package-lock.json | ||
| *.log | ||
This file contains hidden or 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 hidden or 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 hidden or 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,12 +1,13 @@ | ||
| import { Pool, PoolConfig } from 'pg' | ||
| import { parse as parsePgConnectionString } from 'pg-connection-string' | ||
| import { GraphQLSchema } from 'graphql' | ||
| import { GraphQLSchema, GraphQLError } from 'graphql' | ||
| import { EventEmitter } from 'events' | ||
| import { createPostGraphileSchema, watchPostGraphileSchema } from 'postgraphile-core' | ||
| import createPostGraphileHttpRequestHandler, { HttpRequestHandler } from './http/createPostGraphileHttpRequestHandler' | ||
| import exportPostGraphileSchema from './schema/exportPostGraphileSchema' | ||
| import { IncomingMessage, ServerResponse } from 'http' | ||
| import jwt = require('jsonwebtoken') | ||
| import { GraphQLErrorExtended } from './extendedFormatError' | ||
|
|
||
| // Please note that the comments for this type are turned into documentation | ||
| // automatically. We try and specify the options in the same order as the CLI. | ||
|
|
@@ -45,6 +46,14 @@ type PostGraphileOptions = { | |
| // `json` (which causes the stack to become an array with elements for each | ||
| // line of the stack). | ||
| showErrorStack?: boolean, | ||
| // Enables ability to modify errors before sending them down to the client | ||
| // optionally can send down custom responses | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
| /* @middlewareOnly */ | ||
| handleErrors?: (( | ||
| errors: Array<GraphQLError>, | ||
| req: IncomingMessage, | ||
| res: ServerResponse, | ||
| ) => Array<GraphQLErrorExtended>); | ||
| // Extends the error response with additional details from the Postgres | ||
| // error. Can be any combination of `['hint', 'detail', 'errcode']`. | ||
| // Default is `[]`. | ||
|
|
@@ -134,7 +143,7 @@ type PostGraphileOptions = { | |
| // function which will return the same (or a Promise to the same) based on | ||
| // the incoming web request (e.g. to extract session data) | ||
| /* @middlewareOnly */ | ||
| pgSettings?: { [key: string]: mixed } | ((req: IncomingMessage) => Promise<{[key: string]: mixed }>), | ||
| pgSettings?: { [key: string]: mixed } | ((req: IncomingMessage) => Promise<{ [key: string]: mixed }>), | ||
| // Some graphile-build plugins may need additional information available on | ||
| // the `context` argument to the resolver - you can use this function to | ||
| // provide such information based on the incoming request - you can even use | ||
|
|
@@ -161,6 +170,10 @@ export function getPostgraphileSchemaBuilder(pgPool: Pool, schema: string | Arra | |
| console.warn('WARNING: jwtSecret provided, however jwtPgTypeIdentifier (token identifier) not provided.') | ||
| } | ||
|
|
||
| if (options.handleErrors && (options.extendedErrors || options.showErrorStack)) { | ||
| throw new Error(`You cannot combine 'handleErrors' with the other error options`) | ||
| } | ||
|
|
||
| // Creates the Postgres schemas array. | ||
| const pgSchemas: Array<string> = Array.isArray(schema) ? schema : [schema] | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should
return errors- tests can act as demo code.