recurly / recurly-client-dotnet

A .NET API wrapper for Recurly.
https://developers.recurly.com
MIT License
86 stars 80 forks source link

Event Handlers for Async requests resulting in exceptions don't call the OnResponse method #849

Open jweber opened 1 month ago

jweber commented 1 month ago

Event Handlers for Async requests resulting in exceptions don't call the OnResponse method


Describe the bug

Calls that result in an Exception thrown by the client (e.g. NotFound) only call the OnResponse() method of registered event handlers if the call is not made using the Async overloads.

It appears that the HandleResponse method which can throw these exceptions is called before the EventHandlers are in the MakeRequestAsync method, but in the synchronous implementation, HandleResponse is called after the EventHandlers are run.

To Reproduce

Make the same call synchronously and asynchronously that results in a failure using a client with an event handler registered, and observe that the OnResponse method of the event handler is only fired for the synchronous call.

Expected behavior

The OnResponse method for event handlers should fire before an exception is thrown by the HandleResponse method.

Your Environment