microsoft / kiota-abstractions-dotnet

Abstractions library for the Kiota generated SDKs in dotnet
https://aka.ms/kiota/docs
MIT License
24 stars 21 forks source link

ApiException should have a property for parsed response data for parsable error responses #169

Closed hwoodiwiss closed 6 months ago

hwoodiwiss commented 6 months ago

This is related to a suggestion I made here: https://github.com/microsoft/kiota-http-dotnet/issues/188

Description

I think it would make sense that in the case that there is a known Error response type for a given status code, then the response should be parsed (which in the HttpClientRequestAdapter it already is) and added to the ApiException so that is accessible to the calling code handling the exception.

API Changes

To facilitate this, a new property would need to be added to ApiException:

public class ApiException : Exception
{
    public ApiException() : base()
    public ApiException(string message) : base(message)
    public ApiException(string message, Exception innerException) : base(message, innerException)

    public int ResponseStatusCode { get; set; }
    public IDictionary<string, IEnumerable<string>> ResponseHeaders { get; set; }
+   public object? ResponseObject { get; set; }
}

I would then expect the type of the ResponseObject to be disambiguated in calling code.

baywet commented 6 months ago

Holding until we get clarity on the initial issue

hwoodiwiss commented 6 months ago

Closing as this is a non-issue, I missed that the parsed response type is the exception.