Skip to content

ODataError vs ServiceException #2903

@drilko

Description

@drilko

Describe the bug

Hi,

I think there is some confusion about error handling when using MS Graph SDK.

For example, when using DeltaRequestBuilder.GetAsDeltaGetResponseAsync it throws an ODataError, but when using PageIterator<DriveItem, DeltaGetResponse>.CreatePageIterator it throws a ServiceException.

The main problem is that everything is basically null or empty on ServiceException:

  • ResponseHeaders - empty
  • RawResponseBody - null
  • AdditionalData - empty
  • ResponseHeaders - null

There is no proper way to find any relevant information to handle this exception. I've only managed to do it through a Message property like so:

catch (ServiceException ex) when (ex.InnerException?.Message.StartsWith(GraphErrorCode.ResyncRequired.ToString(), StringComparison.OrdinalIgnoreCase) == true)
{
  // Handle the exception
}

Is this a bug or is there a reason for this because the docs mention only ODataError and the upgrade-to-v5 also mentions only ODataError?

Expected behavior

Using PageIterator<DriveItem, DeltaGetResponse>.CreatePageIterator throws an ODataError or relevant properties on ServiceException have values.

How to reproduce

I don't have exact repro steps because what happens is this:

  • First Graph API call is success (using DeltaRequestBuilder.GetAsDeltaGetResponseAsync)
  • Second call via the iterator results in 410 resyncRequired and throws a ServiceException

SDK Version

5.51.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions