swift-openapi-runtime
swift-openapi-runtime copied to clipboard
Add a hook for intercepting decoding errors
Motivation
It's useful for clients to be able to have a centralized way to handle decoding errors, which can be useful for logging or telemetry.
See https://github.com/apple/swift-openapi-generator/issues/522 for more discussion on this.
Modifications
Add a new DecodingErrorHandler protocol which has a single willThrow(_ error: any Error) requirement.
A decoding handler can be passed to the client configuration on initialization.
This is just a proof-of-concept, if this direction is reasonable, it should be fleshed out to handle all decoding paths.
Result
With this change, errors produced by body decoders can be intercepted in a centralized way for all methods going through the Client.
Test Plan
I added a simple unit test. More tests would need to be added to sufficiently cover the functionality being introduced here.
Hi @jpsim - are you still interested in a solution here? I'm happy with either you picking this up again, or letting us take over. It'd just be good to finalize the details with a concrete use case in mind.
I won't be pursuing this further.
I won't be pursuing this further.
May I ask if it's because you found a workflow where you don't need it, or if you don't have the bandwidth to drive the PR?
We're using this library pretty heavily and this would be a fantastic addition that would help us catch a lot of stuff in Datadog instead of finding out API responses aren't decoding properly from customer complaints.
We're open to this enhancement, and with JP closing this PR, I think it'd be appropriate for someone else to open a new PR and we can discuss next steps there.