-
Notifications
You must be signed in to change notification settings - Fork 214
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
Enhance return types to Include HTTP response details #4767
Comments
Thanks for raising this @jake-carpenter At the moment it is possible to implement the With this, you can probably change the response handling to not throw on various Http status code and return a value as you wish. The example below shows how one can use it to get the raw var nativeResponseHandler = new NativeResponseHandler();
await graphClient.Me.GetAsync(requestConfiguration => requestConfiguration.Options.Add(new ResponseHandlerOption(){ ResponseHandler = nativeResponseHandler }));
var responseMessage = nativeResponseHandler.Value as HttpResponseMessage; Any chance this extensibility point works out for you? |
@andrueastman Thank you for bringing that to my attention. It's definitely nice to have that extension point as an option. Ideally I would still like to see the generated code handle this itself to "make doing the right thing easy," but I'm glad to see it already has a flexible core. |
To complement Andrew's answer, you can also use the HeadersInspectionOption to access the headers. |
@baywet As someone who has used various tools like this, I find this disappointing because my experience is that these scenarios significantly increase complexity.
Missing this feature leads to:
Compared to a wrapper that provides the full context of the HTTP response, this approach is certainly not simpler. I don't see it as a critical high-priority feature, but I hope it is reconsidered. |
Thanks for the additional input. For the error status codes, assuming the problem schema is present in the description. The kiota client will deserialize all problem information for you. And the exception will contain the headers + status code. As for accessing the successful response headers/status code/raw body, this is something we're evaluating the design of in #4698 |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. |
Is your feature request related to a problem? Please describe the problem.
One of the major shortcomings in many code generation tools is the assumption that HTTP calls are successful, otherwise throwing an error/exception. It is well-established best practice that try/catch blocks should not be used for flow control; instead, potential failures should be treated as conditions. Cleanly handling this becomes difficult when generated HTTP clients abstract away the details of an HTTP response needed for proper flow control.
The most common need to catch thrown errors/exceptions from generated code occurs with 400-level status codes. Some examples include:
Currently, our only option to handle these non-exceptional cases is to catch the error/exception.
Client library/SDK language
None
Describe the solution you'd like
I would like to see an option to "wrap" or "augment" return types from generated clients to include useful HTTP response information such as:
In C#, where my primary concern lies, a common pattern is to wrap the success type with this additional information. However, other supported languages could use Either/Option/Maybe monads in their idiomatic ways.
It's important to consider that data streams passing between abstractions should be handled carefully. I am not requesting that all data from the HTTP request be included in every case.
Additional context
No response
The text was updated successfully, but these errors were encountered: