-
Notifications
You must be signed in to change notification settings - Fork 1
Return APIErrors directly instead of as a stringified error #22
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
Conversation
|
|
||
| // Check for any errors returned by the API | ||
| if err := r.Errors.ToError(); err != nil { | ||
| return nil, nil, nil, nil, &APIError{e: fmt.Errorf("unexpected error during enrollment: %v", err), ReqID: reqID} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we're no longer capturing the request ID. We log this in mobile_nebula. I think we either need to come up with a solution to continue returning it in APIErrors, or maybe add it to every element in the []APIError (and add it to APIError), .... or just take the easier approach of returning a specific code here (ErrInvalidCode), which will also mean that callers don't all have to parse this themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that lose information if the api server were to return an error other than "invalid code"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you think we might be able to avoid that, and still return an explicit error for invalid codes here? How would the caller do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the server ever returns invalid code along with an additional error. If it did, the caller might want to know that information. So I think what I would do is only return ErrInvalidCode if that's the only error. If there are multiple errors, leave the return as it was before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client.go
Outdated
| return "invalid credentials" | ||
| } | ||
| var InvalidCredentialsError = fmt.Errorf("invalid credentials") | ||
| var InvalidCodeError = fmt.Errorf("invalid enrollment code") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know you were just following the existing code, but these should be in the format ErrInvalidCredentials and ErrInvalidCode.
Since we'll have to update callers anyway (errors.As -> errors.Is for InvalidCredentialsError), I think we should fix the names now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
93ce8c7 to
d3a1c74
Compare

This alters
ToError() errorto beError() stringto allowAPIErrorsto implement the Error interface.