-
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
Add a way to get response body for error responses #5167
Comments
Hi @marcinjahn , |
Hi @baywet, exception containing the content would pretty much solve my issue. |
yes that what I meant |
While I like the suggestion, it would not be an experience that would be seamless across all exceptions. Could we use the work we are doing around UntypedJson to support the body of the exception? |
We could potentially decide to wrap the response into untyped json constructs when we don't have a mapping, and attach that to API error. Of course that assumes the response is JSON |
Transferring issue as part of microsoft/kiota-dotnet#238 |
Moving this to main Repo to track this accross all languages for now. |
Following, this would be an essential feature, not all OpenAPI specs come with proper error mappings unfortunately |
This would solve an important pain point for us. +1. |
I updated the title of this issue to reflect a bit better that this is a request for a new feature |
Thank you for the additional information. In that scenario, are you looking to get the response body only at development time? (while writing and testing the code) or also in production? (app has been deployed for a while, and you don't want to have to re-deploy to enable observability of the body) |
Both development and production. Many OpenAPI specs do not have error mappings, so it doesn’t matter much whether it’s dev or prod from my experience, but I may be missing something.
|
From my perspective, I don't really understand what you mean by "only at development time". My idea was to be able to have some API that would allow you to read the body of error responses. |
The reason why we haven't enabled observing response (or request) bodies "in production" is because it's really easy for anybody to shoot themselves in the foot and start logging data in production. By "only at development time" what I meant is that code could be behind conditional compilation, and only be available with debug builds (for languages that support it) Observing all request/response bodiesThat being said, we have received that request multiple times since the release of kiota. And we could design a similar middleware handler to the HeadersInspectionHandler, name it something like "DangerousBodyInspectionHandler". var observationOption = new DangerousBodyInspectionOption();
var result = await client.Foo.Bar.GetAsync(r => r.Options.Add(observationOption));
observationOption.ResponseBody;
// would be a stream the application would be responsible for disposing This design allows to only copy/observe bodies when requested, lowering IOs. Observing only error responsesThe alternative only for errors is to add a field that would provide access to the response body stream. That field would only be populated if the response was not deserialized to a specific generated type. Which means the cost of errors is higher (memory, IOs), and poses limitations when wanting to observe successful responses or request bodies. Let us know what you think about the two designs. |
|
Thank you for the additional information. @sebastienlevert what do you think of the handler design? What if it didn't have the Dangerous part in the name? |
Is there any temporary workaround we can use to access the response bodies while a proper fix is worked on? |
The only viable option at this point is to implement your own http client middleware handler. |
I like the option of the BodyInspectionOptions, the same way we're doing it for Headers. I don't see this as an issue and this would provide the required capability, while still being an opt-in. I don't think the Dangerous is required. Let's just make sure we don't alter the original response. Having a field on all models with the body content seems overkill and will be more confusing than anything. |
Thanks for the input. Created microsoftgraph/msgraph-sdk-design#116 in our design repo. Once it gets merged, I'll create the individual issues for the http libraries, and close this main issue. |
The design PR has been merged. I also created a bunch of implementation issues (list below) that I recommend anyone following this issue to go subscribe to. Closing to clear confusion. @marcinjahn is this something you'd like to submit a pull request for provided some guidance? If so please jump on the issue for the language you're interested in. Here is the list of issues:
|
I generated a client with Kiota, based on an OpenAPI spec, which does not specify error codes, hence errorMapping is empty in Kiota-generated client. The
ApiException
that Kiota throws contains just the status code and response headers. Is there any way to read the actual response body (as string) without modifying the Kiota-generated client code?The text was updated successfully, but these errors were encountered: