go-openai
go-openai copied to clipboard
Expose APIError required
At present, I don't know how to get the original error message. I need to make conditional judgments based on the original error code to do different things.
Please let me know if you have a solution, thanks
I have the same problem, and I will solve it as soon as possible.
I have the same problem, and I will solve it as soon as possible.
Has there been any progress?
I'm sorry, I haven't finished the wrong refactoring work yet because I've been busy recently.
This can be solved by using errors.As() as seen in the example README. Check out PR comments #293 for implementation details.
e := &openai.APIError{}
if errors.As(err, &e) {
switch e.HTTPStatusCode {
case 401:
// invalid auth or key (do not retry)
case 429:
// rate limiting or engine overload (wait and retry)
case 500:
// openai server error (retry)
default:
// unhandled
}
}
Closing this due to lack of comments for an extended period.