Browse Source

Create AbpExceptionHandlingOptions class

pull/5067/head
liangshiwei 6 years ago
parent
commit
beb95635ab
  1. 11
      docs/en/Exception-Handling.md
  2. 11
      docs/zh-Hans/Exception-Handling.md
  3. 7
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs
  4. 9
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs

11
docs/en/Exception-Handling.md

@ -320,3 +320,14 @@ Some exception types are automatically thrown by the framework:
- `EntityNotFoundException` is thrown if the requested entity is not available. This is mostly thrown by [repositories](Repositories.md).
You can also throw these type of exceptions in your code (although it's rarely needed).
## Send exception details to the client
You can send exceptions to the client via the `SendAllExceptionsToClients` property of the `AbpExceptionHandlingOptions` class:
````csharp
services.Configure<AbpExceptionHandlingOptions>(options =>
{
options.SendAllExceptionsToClients = true;
});
````

11
docs/zh-Hans/Exception-Handling.md

@ -300,3 +300,14 @@ services.Configure<AbpExceptionHttpStatusCodeOptions>(options =>
- 如果请求的实体不存在,则抛出`EntityNotFoundException` 异常. 此异常大多数由 [repositories](Repositories.md) 抛出.
你同样可以在代码中抛出这些类型的异常(虽然很少需要这样做)
## 发送异常详情到客户端
你可以通过 `AbpExceptionHandlingOptions` 类的 `SendAllExceptionsToClients` 属性异常发送到客户端:
````csharp
services.Configure<AbpExceptionHandlingOptions>(options =>
{
options.SendAllExceptionsToClients = true;
});
````

7
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingOptions.cs

@ -0,0 +1,7 @@
namespace Volo.Abp.AspNetCore.ExceptionHandling
{
public class AbpExceptionHandlingOptions
{
public bool SendAllExceptionsToClients { get; set; } = false;
}
}

9
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs

@ -19,20 +19,21 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
{
public class DefaultExceptionToErrorInfoConverter : IExceptionToErrorInfoConverter, ITransientDependency
{
public bool SendAllExceptionsToClients { get; set; } = false;
protected AbpExceptionLocalizationOptions LocalizationOptions { get; }
protected AbpExceptionHandlingOptions ExceptionHandlingOptions { get; }
protected IStringLocalizerFactory StringLocalizerFactory { get; }
protected IStringLocalizer<AbpUiResource> L { get; }
protected IServiceProvider ServiceProvider { get; }
public DefaultExceptionToErrorInfoConverter(
IOptions<AbpExceptionLocalizationOptions> localizationOptions,
IOptions<AbpExceptionHandlingOptions> exceptionHandlingOptions,
IStringLocalizerFactory stringLocalizerFactory,
IStringLocalizer<AbpUiResource> abpUiStringLocalizer,
IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
ExceptionHandlingOptions = exceptionHandlingOptions.Value;
StringLocalizerFactory = stringLocalizerFactory;
L = abpUiStringLocalizer;
LocalizationOptions = localizationOptions.Value;
@ -52,7 +53,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
protected virtual RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception)
{
if (SendAllExceptionsToClients)
if (ExceptionHandlingOptions.SendAllExceptionsToClients)
{
return CreateDetailedErrorInfoFromException(exception);
}
@ -293,4 +294,4 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
return detailBuilder.ToString();
}
}
}
}

Loading…
Cancel
Save