fix: preserve response headers on parsing and stream errors - #922
fix: preserve response headers on parsing and stream errors#922sylvesterkaczmarek wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df0e205eff
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| constructor( | ||
| message: String? = null, | ||
| cause: Throwable? = null, | ||
| private val headers: Headers? = null, |
There was a problem hiding this comment.
Preserve the original Kotlin constructor ABI
Adding headers to the primary constructor changes its synthetic default-argument descriptor; @JvmOverloads preserves the Java overloads but not that Kotlin ABI. A Kotlin consumer compiled against the previous release using OpenAIInvalidDataException("message") invokes the old (String, Throwable, int, DefaultConstructorMarker) constructor and will get NoSuchMethodError after upgrading without recompilation. Keep the original two-parameter primary constructor and introduce header support without replacing its default constructor; the identical change in OpenAIIoException.kt needs the same treatment.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in the latest commits. Both exception classes now keep the original two-parameter primary constructor unchanged and use an internal three-argument secondary constructor only when response headers are available. This preserves the existing Kotlin default-argument constructor ABI while keeping the new optional headers() accessor.
This pull request preserves available HTTP response headers when response parsing or streaming fails, so callers can inspect diagnostics such as
x-request-id.Problem
OpenAIInvalidDataExceptionandOpenAIIoExceptioncurrently carry only a message and cause. This drops response metadata even in error paths where anHttpResponsealready exists:JsonHandlerwraps body read/deserialization failures asOpenAIInvalidDataException.StreamHandlerwraps readerIOExceptions asOpenAIIoException.That makes production debugging harder because callers cannot recover response headers such as
x-request-id.Changes
headers()accessors toOpenAIInvalidDataExceptionandOpenAIIoExceptionresponse.headers()when JSON body parsing failsCompatibility
The original primary constructor signatures and Kotlin default-argument ABI remain unchanged, and the existing Java overloads are preserved. The new header metadata is additive and optional.
Validation
mainat95f4a1173c119ad08a049d752ec67de251434938x-request-idpropagationFixes #690