I would like to know what is the proper way to handle error of GraphQL.
I have sent my request via ApolloClient in TS with an invalid access token to rise an error
The HTTP status code is 200 OK
and the response is
{
"errors": [
{
"message": "Token verification failed: invalid signature",
"path": [
"elements"
]
}
],
"data": {
"elements": null
}
}
I expected whether get 401 Unauthorized
or a code
inside error message like
{
"errors": [
{
"code": "Unauthorized",
"message": "Token verification failed: invalid signature",
"path": [
"elements"
]
}
],
"data": {
"elements": null
}
}
So I can detect that the token is expired by comparing code==='Unauthorized'
I don’t think it’s safe to detect it from message as they are human readable messages and subject to change
My question is:
- In case of server error, how can I detect error type. e.g. to execute refresh token procedure
- Is it safe to simply retry in all errors except authorization and bad request errors?