Skip to content

Close HTTP responses when error handling throws#746

Open
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/close-error-responses
Open

Close HTTP responses when error handling throws#746
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/close-error-responses

Conversation

@fallintoplace
Copy link
Copy Markdown

Summary

  • close non-2xx HttpResponse instances inside errorHandler before throwing typed service exceptions
  • keep 2xx responses open and returned as before
  • copy status, headers, and parsed error data before the response is closed
  • add handler-level tests covering success, typed errors, unexpected statuses, and error body handler failures

Fixes #745.

Test plan

  • JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home ./gradlew :openai-java-core:format
  • JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home ./gradlew :openai-java-core:test --tests com.openai.core.handlers.ErrorHandlerTest
  • JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home ./gradlew :openai-java-core:lint
  • JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home ./gradlew :openai-java-core:test --tests com.openai.services.ErrorHandlingTest

@fallintoplace fallintoplace marked this pull request as ready for review May 19, 2026 18:17
@fallintoplace fallintoplace requested a review from a team as a code owner May 19, 2026 18:17
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.

Non-2xx responses are not closed when error handling throws

2 participants