-
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
Handling non Error instance errors is broken #1393
Comments
@geogeim Can you please describe your use case in more details? |
@IvanGoncharov it's a plain object thrown from a third party npm module (twillio, authy) |
In my opinion feature implemented in #1600 is not enough for some more complex use cases. I have gateway that passes all traffic to sub-services also written in graphql. When subservice returns any error, i want to pass that error directly to client. Currently error is returned in format: "errors": [
{
"message": "Unexpected error value: <JSON_FROM_SUB_SERVICE_HERE>"
}] so to get details like original message, extensions etc - i have to remove "Unexpected error value:" from string and JSON.parse contents - that's hackish. I think better solution would be to join original error into new Error instance: let returnError = new Error('Unexpected error value: ' + (0, _inspect.default)(error));
returnError.originalError = error;
return returnError; @IvanGoncharov what do you think ? |
@marhub You should check if server response return
It was never intended to be a solution for the problem it's just a better error message to help you debug this issue and correctly fix it by constructing In JS we should throw only instances of |
i'm using prisma/graphql-yoga that wraps around apollo server - I could not find any way to do so... edit: please note: gateway = apollo server, it connects to few services ( remote schema ), errors come from those remote services. |
@marhub If we all agree that you should always throw instances of |
@marhub I understand that you want to solve the issue with your particular server. In long run, you should report this issue to |
@IvanGoncharov done some digging and found actual error in apollo/graphql-tools. |
Currently graphql handles resolve error as follows:
This is problematic because if the error is not a string or an instance of
Error
then the error will be serialized as[object Object]
and the workaround (filling up the code with try-catch statements and converting them toError
instances) defeats the purpose of handling errors at the graphql library level.Please provide a configurable mechanism for dealing with errors.
The text was updated successfully, but these errors were encountered: