Asp.net core microsoft graph api-以纯文本形式返回的错误响应

Asp.net core microsoft graph api-以纯文本形式返回的错误响应,asp.net-core,microsoft-graph-api,Asp.net Core,Microsoft Graph Api,我在内部.NETCore3.1WebAPI中使用图形api。但是,每次返回失败的响应时,它都会以500内部错误的形式返回,响应的内容类型为:text/plain Status Code: NotFound Microsoft.Graph.ServiceException: Code: Request_ResourceNotFound Message: Resource '********' does not exist or one of its queried reference-proper

我在内部.NETCore3.1WebAPI中使用图形api。但是,每次返回失败的响应时,它都会以500内部错误的形式返回,响应的内容类型为: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-*******

我希望响应以JSON格式返回,类似于MS Graph Api explorer,带有适当的错误代码,而不是500个内部错误。

我相信您要查找的错误在内部 Microsoft.Graph.ServiceException->错误->代码


如果您想要Json格式,可以使用JsonConverter进行转换。

我认为这种情况与您的要求相同,您可以参考其中的回复:这正是我的问题所在。谢谢@YongqingYu.Thank-ServiceException正是我所忽视的难题中的一块。