-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow fallback for unhandled non-success status codes #340
Comments
Hi @IanKemp I have transferred the issue to this repo since it most likely would not impact the generation. I'll first try to understand the need here before defining the solution. Let me rephrase to make sure I understood things well and please correct me if I missed something: The goal is to be able to access the response body on non-successful response status codes when no factory is registered or when parsing failed. |
Did anything ever happen with this? |
@kieronlanning nothing. I re-closed the issue as not planned to clearly communicate that. |
Thanks @baywet. I have the same issue as the original author I believe: an upstream Open-API that I'm not in control of has undocumented response codes/ error conditions. In this case it's returning an undocumented 400 - but I can't seem to get to the payload to understand what the problem is. |
Since this issue was created, we added support for response body inspection. |
Looking through the GH issue, took me to this page, where it details what support there is for body inspector. It looks as though there is no support for C#, is that correct? |
Thanks for the callout, with the break, we forgot to merge a pull request MicrosoftDocs/openapi-docs#140 |
Ah-ah! Thanks for merging. Will there be a new generator release soonish? |
One is scheduled for tomorrow, but why would you expect a new release? The inspection handler is already available in the kiota dotnet dependencies. |
Oh, it just the documentation that was out of date not the generator itself. Understood. |
Is your feature request related to a problem? Please describe the problem.
Related to microsoft/kiota#3744 which was never satisfactorily addressed. The problem is pretty simple:
The server returned an unexpected status code and no error factory is registered for this code
exceptionNow, I know the maintainers are gonna point me to this, but it doesn't cover a specific scenario: allowing me to see the returned 404 response so that I can either tell the API owner about it so that they fix their spec (because if you've ever worked with "enterprise" companies you know that they require evidence for everything), or fix up my local copy of their spec.
Using a
DelegatingHandler
to throw/log on any unsuccessful responses (HttpResponseMessage.IsSuccessStatusCode == false
) isn't an option because in the given example, it will also throw/log for the 400 case - which it shouldn't, because that's covered by a generated error handler.There is a
Action<RequestConfiguration<T>>
parameter that can be supplied to every Kiota-generated method, and it's possible to specify anIResponseHandler
there that can maybe do what is requested here, but (a) this is on a per-method basis and not a global option (b) as noted here, thatIResponseHandler
isn't in addition to the default Kiota handling but a replacement of it; which rather defeats the point.Client library/SDK language
None
Describe the solution you'd like
Any unsuccessful HTTP response (that is, one where
HttpResponseMessage.IsSuccessStatusCode
isfalse
) will filter through that endpoint's explicit error mappings, exactly as currently.However, in the case that no mapping is found for the returned status code, the library will attempt to resolve an implementation of the below interface:
If such an implementation is found, the problematic
HttpResponseMessage
is passed to this implementation'sHandleAsync
method. After this, Kiota will continue to behave as currently, i.e. throwThe server returned an unexpected status code and no error factory is registered for this code
.In essence, this is inserting a step between the current "look up error mapping for this unsuccessful status code" and "throw if no matching error mapping is found". Because of the way that
HttpClientRequestAdapter
is currently designed, specifically theThrowIfFailedResponse
method, actually implementing this is not simple.Additional context
DelegatingHandler
instead of a whole new interface? maybe? IDK), I don't know how this interface would be provided (a newIRequestOption
implementation?), ...DelegatingHandler
s anyway IIRC... if you want to shoot yourself in the foot, I ain't gonna stop you.)The text was updated successfully, but these errors were encountered: