ASP.NET 样板可用的异常列表和返回的 HTTP 状态代码

ASP.NET Boilerplate available list of exceptions and returned HTTP Status Codes

我正在使用 ASP.NET 样板构建一个 API,它们抽象出了错误处理和 HTTP 状态代码的返回。 我查看了文档,它只提到了 UserFriendlyException 和 AbpValidationException。

我可以使用 ASP.NET 样板及其对应的 HTTP 响应代码抛出哪些其他可用异常 returns?

可用的例外列表是;

  • AbpException
  • UserFriendlyException
  • AbpRemoteCallException
  • AbpValidationException
  • BackgroundJobException
  • EntityNotFoundException
  • AbpAuthorizationException
  • AbpDbConcurrencyException
  • AbpInitializationException

下面是根据GetStatusCode() method的异常和对应的状态码:

  • Abp.AbpException - 500
  • Abp.AbpInitializationException - 500
  • Abp.Authorization.AbpAuthorizationException - could be 403 or 401
  • Abp.BackgroundJobs.BackgroundJobException - 500
  • Abp.Domain.Entities.EntityNotFoundException - 404
  • Abp.Domain.Uow.AbpDbConcurrencyException - 500
  • Abp.Runtime.Validation.AbpValidationException - 400
  • Abp.UI.UserFriendlyException - 500
  • Abp.WebApi.Client.AbpRemoteCallException - 500
protected virtual HttpStatusCode GetStatusCode(HttpActionExecutedContext context)
    {
        if (context.Exception is Abp.Authorization.AbpAuthorizationException)
        {
            return AbpSession.UserId.HasValue
                ? HttpStatusCode.Forbidden
                : HttpStatusCode.Unauthorized;
        }

        if (context.Exception is AbpValidationException)
        {
            return HttpStatusCode.BadRequest;
        }

        if (context.Exception is EntityNotFoundException)
        {
            return HttpStatusCode.NotFound;
        }

        return HttpStatusCode.InternalServerError;
    }

Available exceptions from docs