shurcooL / graphql

Package graphql provides a GraphQL client implementation.
MIT License
709 stars 282 forks source link

Return more verbose error to the caller #99

Open rjjatson opened 2 years ago

rjjatson commented 2 years ago

Hi, There is currently no way to differentiate between various errors when doing a query/ mutation except from the error messages.

As error messages from the resource server are sometimes dubiety, some resource server does return error code on the extensionsfield so that the callers could identify the errors. Thus, I believe it would be very convenient if this package could provide a way to let the caller get the error's extensions value.

I am thinking something like what aws sdk does on their awserr. I would like to do something like this :

if err != nil {
    if gqlErr, ok := err.(graphql.Error); ok {
        // process error
        // if gqlErr.Code() == ...
    }
}

So im taking my chance to ask if there is any possibility that you could export the graphql.errors type and let the caller get whatever it is inside the extension? I could try to implement it if the idea sounds worth to do. Or at least i would like to hear your opinion about handling various errors from the resource server.

Thanks !

rjjatson commented 1 year ago

https://github.com/shurcooL/graphql/pull/98 i believe having that one PR released would do the job. wonder if any maintainers noticed it @dmitshur