msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

[Client bug]: Service exceptions don't match with any error from GraphErrorCode.cs

Open Yevhenii-Prodan opened this issue 4 years ago • 5 comments

Describe the bug I'm trying to catch errors when I create subscription on outlook calendar, and I wrote something like this

 try {
//some code...
}
catch(ServiceException e) {
if (e.IsMatch(GraphErrorCode.Unauthenticated.ToString())) {
    //some code 
    }

}

according to https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/errors.md but it did't work. Then I've tried every error from GraphErrorCode, but any of them didn't work. How should I recognize, whitch error I've caught?

AB#7265

Yevhenii-Prodan avatar Dec 27 '19 11:12 Yevhenii-Prodan

What value do you get for e.Error.Code? I suspect that the error code is not set. This may be a scenario that doesn't have a map.

MIchaelMainer avatar Jan 02 '20 18:01 MIchaelMainer

Message of error is

Status Code: Unauthorized Microsoft.Graph.ServiceException: Code: InvalidAuthenticationToken Message: CompactToken validation failed with reason code: 80049228.

Yevhenii-Prodan avatar Jan 08 '20 11:01 Yevhenii-Prodan

for now I recognize errors via HttpStatusCode enum

Yevhenii-Prodan avatar Jan 08 '20 11:01 Yevhenii-Prodan

This is really a documentation bug. We shouldn't have attempted to do error mapping with the client since there are way too many services errors in the Microsoft Graph ecosystem for us to realistically map. Errors should pass through. We will not add new error mappings, and we should deemphasize the use of the GraphErrorCodes file.

MIchaelMainer avatar Feb 20 '20 22:02 MIchaelMainer

This still appears to be an issue. eg. the service returns the error code Request_ResourceNotFound not Microsoft.Graph.GraphErrorCode.ItemNotFound ("ItemNotFound").

Errors should pass through. We will not add new error mappings, and we should deemphasize the use of the GraphErrorCodes file.

Perhaps a set of string constants might make it more clear that they're non-exhaustive while still saving on typo's etc?

fowl2 avatar Oct 13 '22 08:10 fowl2

@andrueastman can you verify this was cleaned up with V5 and close if so.

ddyett avatar Jun 28 '23 01:06 ddyett

Closing this one for now as error handling is different in V5. Documentation was updated to cover status code matching. GraphErrorCodes still exists but is not meant to be exhaustive but only capture common error codes documented in the service documentation. https://learn.microsoft.com/en-us/graph/errors

andrueastman avatar Aug 17 '23 07:08 andrueastman