openai-java
openai-java copied to clipboard
Unwrap SocketTimeoutException and update tests accordingly
Hi, thanks for the great work, it's very simple and easy to use.
When working with the library I found it a bit strange that currently the API returns an OpenAiHttpException when the token-per-minute wall is met but only a generic RuntimeException when a timeout on the OpenAI APIs is reached. This is a bit counterintuitive to me because, in order to catch it, I have to get the parent exception via the getCause()
method and check if this was rather of type SocketTimeoutException
.
This PR raises the level of the exception to the more specific SocketTimeoutException
, so that it's easier on the client-side to handle these cases. Tests are updated accordingly so to pass successfully.
Note that this exception could easily be integrated into an OpenAiHttpException
as I believe mean similar concepts. Still, I didn't make the effort to do it but could be easily integrated to this PR.
@TheoKanning @aaronuu @Grogdunn