You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
3 years ago
|
using System;
|
||
|
using System.Net;
|
||
|
using Volo.Abp.Http;
|
||
|
|
||
|
namespace Sanhe.Abp.Wrapper;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 异常包装上下文。
|
||
|
/// </summary>
|
||
|
public class ExceptionWrapContext
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 异常
|
||
|
/// </summary>
|
||
|
public Exception Exception { get; }
|
||
|
/// <summary>
|
||
|
/// 服务提供器
|
||
|
/// </summary>
|
||
|
public IServiceProvider ServiceProvider { get; }
|
||
|
/// <summary>
|
||
|
/// 用于存储有关错误的信息
|
||
|
/// </summary>
|
||
|
public RemoteServiceErrorInfo ErrorInfo { get; }
|
||
|
/// <summary>
|
||
|
/// 状态码
|
||
|
/// </summary>
|
||
|
public HttpStatusCode? StatusCode { get; set; }
|
||
|
|
||
|
public ExceptionWrapContext(
|
||
|
Exception exception,
|
||
|
RemoteServiceErrorInfo errorInfo,
|
||
|
IServiceProvider serviceProvider,
|
||
|
HttpStatusCode? statusCode = null)
|
||
|
{
|
||
|
Exception = exception;
|
||
|
ErrorInfo = errorInfo;
|
||
|
ServiceProvider = serviceProvider;
|
||
|
StatusCode = statusCode;
|
||
|
}
|
||
|
|
||
|
public ExceptionWrapContext WithCode(string code)
|
||
|
{
|
||
|
ErrorInfo.Code = code;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public ExceptionWrapContext WithMessage(string message)
|
||
|
{
|
||
|
ErrorInfo.Message = message;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public ExceptionWrapContext WithDetails(string details)
|
||
|
{
|
||
|
ErrorInfo.Details = details;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public ExceptionWrapContext WithData(string key, object value)
|
||
|
{
|
||
|
ErrorInfo.Data[key] = value;
|
||
|
return this;
|
||
|
}
|
||
|
}
|