unchase/Unchase.OpenAPI.Connectedservice

Typed ApiException would always be thrown with empty string for Message

Closed this issue · 1 comments

Suppose an API call returns an erroneous status with an object for its body (say, ProblemDetails or something similar), the generated code fetches the reponse object via a call to ReadObjectResponseAsync where T is the payload type, according to the OpenAPI specs.
ReadObjectResponseAsync(), in the part where it successfully deserializes the payload into the templated type, creates an ObjectResponseResult object with string.Empty for responseText, which is fair enough - how can it guess what text to put there if all it has is an object of some type. But look, then we are back in the request method with the instance of ObjectResponseResult which has string.Empty in Text. And then the code immediately throws an ApiException and sends objectResponse_.Text into the response parameter and ApiException goes up with guaranteeed string.Empty in Response.
What would make me happy, is a hook somewhere in there to be able to generally populate Response property with help of my own logic which would work with my "ProblemDetails" classes whatever they might be. You have PrepareRequest() and ProcessResponse() partial methods, I would humbly suggest something like PrepareApiException() which would take objectResponse_ and maybe response_ and a "half-baked" ApiException instance and return the completed ApiException.

Hi, @ymakassiouk
The Connected Service based on NSwag.

Should create the same issue in this place.