msgraph-sdk-dotnet
msgraph-sdk-dotnet copied to clipboard
[Client bug]: Service exceptions don't match with any error from GraphErrorCode.cs
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?
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.
Message of error is
Status Code: Unauthorized Microsoft.Graph.ServiceException: Code: InvalidAuthenticationToken Message: CompactToken validation failed with reason code: 80049228.
for now I recognize errors via
HttpStatusCode
enum
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.
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?
@andrueastman can you verify this was cleaned up with V5 and close if so.
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