Skip to content

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.

2 participants