swift-openapi-runtime icon indicating copy to clipboard operation
swift-openapi-runtime copied to clipboard

Add a hook for intercepting decoding errors

Open jpsim opened this issue 1 year ago • 1 comments

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.

jpsim avatar Feb 04 '24 02:02 jpsim

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.

czechboy0 avatar Oct 03 '24 17:10 czechboy0

I won't be pursuing this further.

jpsim avatar Jan 15 '25 20:01 jpsim

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?

czechboy0 avatar Jan 15 '25 20:01 czechboy0

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.

daviduzumeri avatar Jan 17 '25 16:01 daviduzumeri

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.

czechboy0 avatar Jan 17 '25 20:01 czechboy0