Skip to content

Inconsistency with GraphError's code property and GraphErrorCodes.ITEM_NOT_FOUND #606

@GeertZijlmans1

Description

@GeertZijlmans1

Expected behavior

When a GraphError's code field has the value "ErrorItemNotFound", then GrapError#isError method should return true for GraphErrorCodes.ITEM_NOT_FOUND.

Actual behavior

I have a catch-block for a GraphServiceException and I'm checking the error code that is returned. This check uses GraphError#isError. For GraphErrorCodes.ITEM_NOT_FOUND this check returns false, whereas the log shows:

CoreHttpProvider[sendRequestInternal] - 408Graph service exception
Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: ErrorItemNotFound
Error message: The specified object was not found in the store.

Steps to reproduce the behavior

  1. Create code similar to the code below and verify that for a non-existing Event ID it will return a GraphServiceException with code "ErrorItemNotFound", yet it will not log the line as stated in the exception.

`
try
{
graphServiceClient.users(resourceIdentifier) //
.events(eventId)//
.decline(EventDeclineParameterSet.newBuilder().withSendResponse(false).build())
.buildRequest()//
.post();

       // Decline it twice to get the ErrorItemNotFound exception
       graphServiceClient.users(resourceIdentifier) //
            .events(eventId)//
            .decline(EventDeclineParameterSet.newBuilder().withSendResponse(false).build())
            .buildRequest()//
            .post();
        
        LOG.info(String.format("Declined event for ID <%s> for Resource <%s>", eventId, resourceIdentifier), aContext);
    }
    catch (GraphServiceException aException)
    {
        // Item not found so nothing to decline, proceed as if it was a success
        if (aException.getServiceError().isError(GraphErrorCodes.ITEM_NOT_FOUND))
        {
             LOG.info(String.format("No need to decline event for ID <%s> for Resource <%s> as it was already not present", eventId, resourceIdentifier), aContext);
        }
    }

`

Expected solution

Expected problem is the comparison made in GraphError#transformErrorCodeCase

Where "ErrorItemNotFound" is compared to ITEM_NOT_FOUND, this yields false as either the code should have been "ItemNotFound" or GraphErrorCodes.ERROR_ITEM_NOT_FOUND should have existed.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions