0

I'm using the the graph api in an internal .Net Core 3.1 webapi. However, each time a failed response is returned, it returns as a 500 internal error with the response as content-type: text/plain.

Status Code: NotFound
Microsoft.Graph.ServiceException: Code: Request_ResourceNotFound
Message: Resource '********' does not exist or one of its queried reference-property objects are not present.
Inner error:
    AdditionalData:
    date: 2020-10-13T13:44:21
    request-id: 8053255b-2f1c-4543-8de7-*******
    client-request-id: 8053255b-2f1c-4543-8de7-*******
ClientRequestId: 8053255b-2f1c-4543-8de7-*******

I am looking for the response to be return in JSON format similarly to the MS Graph Api explorer with the appropriate error code instead of a 500 Internal Error.

rickyzu
  • 13
  • 3
  • I think this case is the same as your requirement, you can refer to the reply in it:https://stackoverflow.com/questions/62438792/microsoft-graph-error-responses-how-to-extract-http-status-code-and-inner-erro – LouraQ Oct 14 '20 at 09:34
  • This is exactly what my issue was. Thanks @YongqingYu. – rickyzu Oct 14 '20 at 10:18

1 Answers1

0

I believe the error you're looking for is inside Microsoft.Graph.ServiceException -> Error -> Code.

If you'd like it in Json format you could convert it using JsonConverter.

Dani Mazahreh
  • 50
  • 1
  • 1
  • 12