Skip to content

Microsoft Graph API Exception failing to deserialize and is thrown as ApiException instead of ODataError #2468

Description

@gabrielav1599

Describe the bug

We are using the DriveItemRequestBuilder.GetAsync method. From our logs, the MS Graph API returned a 503 on the request. We have a try catch around the DriveItemRequestBuilder.GetAsync method with a catch for ODataError, but this catch wasn't executed. The method threw an ApiException instead and we got the following stack trace:

Microsoft.Kiota.Abstractions.ApiException: The server returned an unexpected status code and the error registered for this code failed to deserialize: 503\r\n at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken)\r\n at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)\r\n at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)\r\n at Microsoft.Graph.Shares.Item.DriveItem.DriveItemRequestBuilder.GetAsync(Action1 requestConfiguration, CancellationToken cancellationToken)\r\n

The error message is coming from Kiota: https://github.com/microsoft/kiota-http-dotnet/blob/c1c295d3b0ebb2182b66d9a6858241117b59b540/src/HttpClientRequestAdapter.cs#L415C1-L416C1

Please let me know if there is any additional I can provide. Thanks!

Expected behavior

We would expect the 503 to return as an OData Error, or confirm whether the intended behavior instead is for errors to throw an ApiException instead.

How to reproduce

The repro would involve calling the DriveItemRequestBuilder.GetAsync method and mocking a 503 response from Graph API.

SDK Version

5.41.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions