Skip to content
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

C# - Kiota swallows exception body when undocumented exception is thrown #3964

Closed
Ksdmg opened this issue Jan 3, 2024 · 7 comments
Closed
Assignees
Labels
enhancement New feature or request help wanted Issue caused by core project dependency modules or library Status: No Recent Activity

Comments

@Ksdmg
Copy link

Ksdmg commented Jan 3, 2024

When no errorMapping exists, the response body does not get included in the thrown ApiExcepion:

https://github.com/microsoft/kiota-http-dotnet/blob/3c35d1c3c350c4b208e46b7c8bf8c93d518df916/src/HttpClientRequestAdapter.cs#L399C31-L399C31

I think you should include the full HttpResponseMessage as it is really helpful if you face undocumented exceptions.

@darrelmiller
Copy link
Member

Would you be OK with the response body as a string? We can't return the native type as we don't want to take a dependency on it.

@Ksdmg
Copy link
Author

Ksdmg commented Jan 4, 2024

Yes a simple string in the exception would help alot.
My proposed solution would be to add an ExceptionHandler as a QueryOption. This would allow us to create a custom exception handler that handles the payload without throwing.

@baywet
Copy link
Member

baywet commented Jan 8, 2024

@darrelmiller what would you want to be done when the payload is large and/or is "not a string"? (let's imagine the client gets an image back).
@Ksdmg this is something you'd be able to do today by implementing a custom middleware handler and a custom query option + inserting the handler in the middleware configuration of the HTTP client. Is this something you'd want to explore to provide a demonstration?

@baywet baywet added enhancement New feature or request help wanted Issue caused by core project dependency modules or library Needs: Author Feedback labels Jan 8, 2024
@baywet baywet added this to the Backlog milestone Jan 8, 2024
@Ksdmg
Copy link
Author

Ksdmg commented Jan 9, 2024

@baywet would be awesome if you could give me an example of how to do it. I tried to do it with the ResponseHandler but this leads to additional code that I need to put into every request because it does not return a value even if the request is successful.

@baywet
Copy link
Member

baywet commented Jan 9, 2024

Here is an example of the retry handler

and its option

I suggest you implement a "Default Error Mapping option & handler". The option would contain a dictionary of status code and type mapping.

Then you'd need to build your http client by inserting your new middleware in the collection

And lastly, when you make your request with the fluent API, you can pass the option thanks to the request configuration (client.Foo.Bar.GetAsync(x => x.Options.Add(MyOptionInstance))

Copy link
Contributor

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.

1 similar comment
Copy link
Contributor

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.

@microsoft-github-policy-service microsoft-github-policy-service bot removed this from the Backlog milestone Jan 17, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Kiota Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Issue caused by core project dependency modules or library Status: No Recent Activity
Projects
Archived in project
Development

No branches or pull requests

3 participants