403 and 401 errors in ABP Framework not returning response body

198 views Asked by At

I'm working with ABP framework, I have an issue with abp version 5 and above. When I make a request to an endpoint and I'm not authorized, the response code is 401 which is what I expect, but the response body is empty. At first I suspected that this is the normal behavior and I need to handle the exception myself, but then I found in the app logs that the response I'm looking for is being logged but not returned. enter image description here

The logs is showing:

 [01:18:04 WRN] ---------- RemoteServiceErrorInfo ----------
{
  "code": "Volo.Authorization:010001",
  "message": "Authorization failed! Given policy has not granted.",
  "details": null,
  "data": {},
  "validationErrors": null
}

[01:18:04 WRN] Exception of type 'Volo.Abp.Authorization.AbpAuthorizationException' was thrown.
Volo.Abp.Authorization.AbpAuthorizationException: Exception of type 'Volo.Abp.Authorization.AbpAuthorizationException' was thrown.

In the earlier versions of ABP (4.4.4 and before), this response was being returned normally.

I've tried handling the exception but I then saw that it is being catched somewhere in the framework. Not sure if this could be related to OpenIdDict, as in the earlier versions the abp was using IdentityServer.

1

There are 1 answers

0
Evram Ehab On

You can override the DefaultExceptionToErrorInfoConverter.

You can find more info about it here:

https://github.com/abpframework/abp/issues/17949

I hope this answers your question as I have a similar requirement and found this solution, but never implemented it myself.