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

Improve error reporting #68

Merged
merged 3 commits into from
Feb 13, 2023

Conversation

DarkDust
Copy link
Contributor

The errors returned by sendRequest did not allow for easy error inspection. This PR aims to improve this.

To be able to test what type of error was returned by the server, an APIError struct is introduced which is basically the previous ErrorResponse.Error struct, but with three changes:

  • The Code field's type has been fixed, it's a string.
  • An additional field StatusCode int field was added to transport the HTTP status code as well.
  • Implements the Error interface.

There's also a new RequestError for errors which do not provide an API error object.

The errors returned by sendRequest now make use of error wrapping via %w. This way the returned error strings retain their previous format but errors.Is and errors.As now work to get access to the additional error information.

@sashabaranov
Copy link
Owner

Thank you for the PR, it's really thoughtful! 🔥

I would love to merge once linter is happy 😄

@DarkDust
Copy link
Contributor Author

Sorry, I forgot to run gofmt after a change. Fixed now. :-)

@sashabaranov sashabaranov merged commit ee3df71 into sashabaranov:master Feb 13, 2023
@DarkDust
Copy link
Contributor Author

That was fast, thank you very much!

@sashabaranov
Copy link
Owner

@DarkDust sure, thank you so much! Future note: I think there might be some room for error-reporting improvements in stream.go if you are up for it :D

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.

None yet

2 participants