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(errors): return actionable errors from API #13

Merged
merged 1 commit into from
Jun 22, 2016

Conversation

Joshua-Anderson
Copy link
Contributor

@Joshua-Anderson Joshua-Anderson commented Jun 21, 2016

This tries to strike a balance between supporting every possible error, which is infeasible because of how many (undocumented) errors exist, and supporting the most useful errors.

The most useful errors have their own type, and the less common errors return a unknown error.

@Joshua-Anderson Joshua-Anderson self-assigned this Jun 21, 2016
@Joshua-Anderson
Copy link
Contributor Author

I also intend to add a func IsUnkownError(err error) bool so that it is easy to check to see if the error was not recognized.

case 400:
bodyMap := make(map[string]interface{})
if err := json.NewDecoder(res.Body).Decode(&bodyMap); err != nil {
return ErrParsing
Copy link
Member

Choose a reason for hiding this comment

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

perhaps we should also return the response body so the user can determine the error on their own?

if err != nil {
return api.App{}, err
}
// Fix json.Decoder bug in <go1.7
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be // TODO: Remove when json.Decoder bug is fixed (go >= 1.7) ? It's unfortunate that this has to be repeated everywhere Decode is used.

Also do you have a reference for this json.Decoder issue? Just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was caught in google's github-api repo: google/go-github#317

I'll make a PR to reformat the warning to what you suggested everywhere.

@Joshua-Anderson Joshua-Anderson changed the title [WIP] fix(errors): return actionable errors from API fix(errors): return actionable errors from API Jun 21, 2016
@Joshua-Anderson
Copy link
Contributor Author

This is no longer WIP. @helgi you had some concerns about my approach, could you please review?

@Joshua-Anderson
Copy link
Contributor Author

Joshua-Anderson commented Jun 22, 2016

@bacongobbler You accidentally LGTMed this twice ❤️! I removed your second LGTM so somebody else can review it.

@bacongobbler
Copy link
Member

whoops :P

@helgi
Copy link
Contributor

helgi commented Jun 22, 2016

I'd rather want to fix the API where possible with more identifable information than to parse things like this but good enough for now. An improvement for sure

@Joshua-Anderson Joshua-Anderson merged commit 1bbb1c7 into deis:master Jun 22, 2016
@Joshua-Anderson Joshua-Anderson deleted the errors branch June 22, 2016 19:32
cscatolini pushed a commit to topfreegames/controller-sdk-go that referenced this pull request Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants