Skip to content
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

401 Unauthorized returns nondescript error #118

Open
arbourd opened this issue Mar 28, 2022 · 0 comments
Open

401 Unauthorized returns nondescript error #118

arbourd opened this issue Mar 28, 2022 · 0 comments

Comments

@arbourd
Copy link

arbourd commented Mar 28, 2022

If the API returns a 401, like if a bad token is passed into the client constructor, all errors will appear as internal error, response body doesn't match error type signature.

This is caused by the error message being non-standard from the API in:

// json.Unmarshal doesn't return an error if the response
// body has a different protocol then "ErrorResponse". We
// check here to make sure that errorRes is populated. If
// not, we return the full response back to the user, so
// they can debug the issue.
// TODO(fatih): fix the behavior on the API side
if *errorRes == (errorResponse{}) {
return &Error{
msg: "internal error, response body doesn't match error type signature",
Code: ErrInternal,
Meta: map[string]string{
"body": string(out),
"http_status": http.StatusText(res.StatusCode),
},
}
}

The response from the API is:

{"error":"invalid_token","error_description":"The access token is invalid","state":"unauthorized"}

The TODO is almost a year old. Is it worth adding a 2nd (deprecated) ErrorResponse type to handle this other structure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant