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

Update APIError.Error() to provide more helpful error messages #334

Merged
merged 1 commit into from
Oct 9, 2021

Conversation

theckman
Copy link
Collaborator

While refactoring the API handling with the APIError type, we gave callers
more capability to inspect the errors that come from the API so that we can
handle them. Unfortunately, in the process we lost some fidelity in the strings
returned by its Error() method, compared to how errors used to be handled.

This updates the APIError.Error() method to now include the first detailed
error string provided from the API, if there is one, and incidate how many more
existed in the response (without printing them). This should help keep the error
tidy, while making it actionable by consumers. Consumers of this package are
still encouraged to deeply inspect the error, to handle each one.

This was inspired by #327, which the reporter closed after learning how to
deeply inspect the returned error value.

While refactoring the API handling with the `APIError` type, we gave callers
more capability to inspect the errors that come from the API so that we can
handle them. Unfortunately, in the process we lost some fidelity in the strings
returned by its `Error()` method, compared to how errors used to be handled.

This updates the `APIError.Error()` method to now include the first detailed
error string provided from the API, if there is one, and incidate how many more
existed in the response (without printing them). This should help keep the error
tidy, while making it actionable by consumers. Consumers of this package are
still encouraged to deeply inspect the error, to handle each one.

This was inspired by #327, which the reporter closed after learning how to
deeply inspect the returned error value.
Copy link
Contributor

@stmcallister stmcallister left a comment

Choose a reason for hiding this comment

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

This is smart. Thanks for the update!

@theckman theckman merged commit 9326bd9 into master Oct 9, 2021
@theckman theckman deleted the better_error_strings branch October 9, 2021 20:55
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