-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
transformSchema handles errors incorrectly #1367
Comments
Additional info: It seems that when we are logging the error, we also call: require('apollo-errors').formatError(error); This should unwrap the originalError parameter. However somewhere along the way in the Apollo/GraphQL code, the ApolloError type is lost and the originalError is of type Object. As a result the fields needed are missing. |
As a workaround what I did was:
Now I am working with the correct error: thrownError. Note: the contract to formatError shouldn't change depending if I use transformSchema or not. If I throw an error, formatError should expect to get that error that I had thrown. |
= combineErrors now returns the originalError if one is present. = relocating an error is not necessary prior to throwing, and may cause the original error to be lost. = The CombinedError class now inherits from GraphQLError rather than directly from error to utilize its methods of properly allow extending the base Error class. Hopefully fixes #1367.
= combineErrors now returns the originalError if one is present. = relocating an error is not necessary prior to throwing, and may cause the original error to be lost. = The CombinedError class now inherits from GraphQLError rather than directly from error to utilize its methods of properly allow extending the base Error class. Hopefully fixes #1367.
@tomkoufakis not 100% sure this will fix your issue but I think it heads in the right direction and may actually work. Just curious whether this was working in v4. |
Hopefully fixed with latest alpha, |
Closed by #1419. |
PROBLEM DESCRIPTION:
If I throw a custom exception from inside a resolver using:
const createError = require('apollo-errors').createError; createError('SearchAPIError', { data: { code: '5xx' }, message: 'SearchAPI Error', { showPath: true, showLocations: true } })
The transformSchema call:
publicExecutableSchema = transformSchema(publicExecutableSchema, [ new FilterAndTransformSchema(publicSchemaConfig, config.public.strict) ]);
Normally without calling transformSchema, the errors returned from the GQL API might look like:
{ "errors": [ { "message": "SearchAPI Error", "locations": [ { "line": 2, "column": 3 } ], "path": [ "home_search" ], "name": "SearchAPIError", "time_thrown": "2020-04-15T17:12:35.189Z", "data": { "code": "5xx", "error": "ValidationMessage", "message": "\"limit\" must be less than or equal to 200", "description": "A validation error occurred" } } ] ....
However when I use transformSchema I find that name, time_thrown, and data fields are stripped out of the error object. The stack trace also follows a different path when transformSchema is in the mix. With transformSchema I lose the stack trace of the actual error and instead get a path related to "new CombinedError (....". The exception type thrown is GraphQLError instead of SearchAPIError.
Cases:
INTENDED OUTCOME:
ACTUAL OUTCOME:
HOW TO REPRODUCE THE ISSUE:
The text was updated successfully, but these errors were encountered: