Skip to content

Close error responses before throwing#765

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

Close error responses before throwing#765
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/error-handler-closes-responses

Conversation

@fallintoplace

Copy link
Copy Markdown

Summary

  • close HTTP responses inside errorHandler before throwing on non-2xx statuses
  • keep 2xx responses open so the normal parse path still owns them
  • add focused regression tests for successful pass-through, parsed 400 errors, and malformed 400 error bodies

Why

Generated services call errorHandler.handle(response).parseable { response.use { ... } }. On 4xx/5xx responses, errorHandler.handle(response) throws before the response.use { ... } parse block runs, so the response could remain open after the error body was parsed.

Impact

This closes the leak once in the shared error-handling path, which covers both blocking and async generated services without touching every endpoint implementation.

Validation

  • env JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home PATH=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home/bin:$PATH ./gradlew :openai-java-core:test --tests com.openai.core.handlers.ErrorHandlerTest
  • env JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home PATH=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home/bin:$PATH ./gradlew :openai-java-core:lintKotlin

@fallintoplace fallintoplace requested a review from a team as a code owner June 27, 2026 20:58
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.

1 participant