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

Fix json error handling #23

Merged
merged 2 commits into from
May 18, 2020
Merged

Fix json error handling #23

merged 2 commits into from
May 18, 2020

Conversation

eguzki
Copy link
Member

@eguzki eguzki commented May 18, 2020

For JSON endpoints, when 3scale API returns http.StatusUnprocessableEntity response status code, the body contains the specific error format:

struct {                               
    Errors map[string][]string `json:"errors"`   
}                                              

For instance:

{"errors":{"system_name":["has already been taken"]}}

Current implementation was shadowing the actual error with decoding error as it was trying to parse with

map[string]string

For the generic error response, the body is just readed and not parsed. This breaks backwards compatibility for a given set of endpoints, resulting a slightly different error message than before. For example:
Before:

error calling 3scale system - reason: error - Your access token does not have the correct permissions - code: 403"

Now:

error calling 3scale system - reason: { "error": "Your access token does not have the correct permissions" } - code: 403

If this an inconvenience, the code may be improved to process specific cases. Which I do not think so, but asking for safety :)

@eguzki eguzki requested a review from philipgough May 18, 2020 13:39
Copy link
Contributor

@philipgough philipgough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eguzki - I don't see an issue with this change. The errors are unexported so users would not be expected to test against the error code regardless. I don't see it breaking anything we use internally and besides that, the api is alpha so happy to merge.

@eguzki eguzki merged commit c2e3a7f into master May 18, 2020
@eguzki eguzki deleted the fix-json-error-handling branch May 18, 2020 15:19
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

Successfully merging this pull request may close these issues.

2 participants