-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add BadUserInputError and TransientError as extensions of ApolloError #1143
Conversation
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.
BadUserInputError
is a great addition! Adding it and the other errors to the api reference would be awesome too. Pointing to the error reference section in the error handling section would make them more visible as well!
I think for now TransientError
would be better as a suggested pattern, rather than a baked in error. Currently the name seems a bit too general and its functionality isn't super well specified. As we build the capabilities into apollo server, such as rate limiting, it could be confusing.
} | ||
} | ||
|
||
export class TransientError extends ApolloError { |
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.
Let's leave the TransientError
out for now, since we don't have a compelling use case on the client-side. It seems like the best place to handle theses sorts of errors is either in the layer above the GraphQL execution, such as middleware, or in the Data sources, which could retry on their own. I totally agree that we want this sort of retriability. I'm just not convinced that an error in the resolvers is the right place.
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.
I agree with you. Let's keep it as a suggested pattern so that our use cases for ApolloError stays solid!
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.
Working updating the error handling section of the docs as well. What do you feel about moving some of the code examples from my blog over as well once they have been reviewed?
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.
Totally! We can move them over now too if you prefer
errorClass: BadUserInputError, | ||
name: 'BadUserInputError', | ||
}); | ||
console.log(`error: ${JSON.stringify(error, null, 2)}`); |
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.
We should remove logs from the code. Ideally it would be caught in the linting step. I guess prettier doesn't do that for us anymore 😢
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.
Yes thanks for catching that🙏🙏
We should also make sure that the base branch is version-2, rather than the old refactor-2.0 |
@evans the tests are now failing because I updated it so that it checks for |
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.
@clarencenpy Great stuff! After we get the tests passing, plus new screenshot and a couple cosmetic changes to the code samples, we'll be all set.
@@ -101,12 +96,20 @@ The response will return: | |||
|
|||
![Screenshot demonstrating augmented error](../images/features/error-user-input.png) |
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.
We should update this screenshot to match the new code
@@ -43,11 +42,7 @@ The response will return: | |||
In addition to stacktraces, Apollo Server's exported errors specify a human-readable string in the `code` field of `extensions` that enables the client to perform corrective actions. In addition to improving the client experience, the `code` field allows the server to categorize errors. For example, an `AuthenticationError` sets the code to `UNAUTHENTICATED`, which enables the client to reauthenticate and would generally be ignored as a server anomaly. | |||
|
|||
```js line=4,15-17 |
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.
These highlighted lines should line up with the AuthenticationError and it's usage, so I think we want to keep them on separate lines even though it might not match Prettier's styling
errorClass: BadUserInputError, | ||
name: 'BadUserInputError', | ||
}); | ||
expect(error.extensions.exception.field1).to.equal('property1'); |
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.
We can make these fields on the root error. The important part is for when these errors are thrown in resolvers to contain the correct layout. Here for example
@evans should be good to go! |
@clarencenpy Awesome work! We'll release this in the next beta 🎉 |
Purely talking points:
|
@abernix My apologies, should have seen your comments earlier!
|
Proposed additions of two new error types. They are just simple wrappers around the ApolloError interface, and could be used to highlight more use cases of using ApolloErrors.
TODO: