本文整理汇总了C#中System.Exception.ToErrorResponse方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.ToErrorResponse方法的具体用法?C# Exception.ToErrorResponse怎么用?C# Exception.ToErrorResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.ToErrorResponse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteErrorToResponse
public static void WriteErrorToResponse(this IHttpResponse httpRes, IHttpRequest httpReq,
string contentType, string operationName, string errorMessage, Exception ex, int statusCode)
{
var errorDto = ex.ToErrorResponse();
if (HandleCustomErrorHandler(httpRes, httpReq, contentType, statusCode, errorDto)) return;
if (httpRes.ContentType == null || httpRes.ContentType == ContentType.Html)
{
httpRes.ContentType = contentType;
}
if (EndpointHost.Config.AppendUtf8CharsetOnContentTypes.Contains(contentType))
{
httpRes.ContentType += ContentType.Utf8Suffix;
}
httpRes.StatusCode = statusCode;
var serializationCtx = new SerializationContext(contentType);
var serializer = EndpointHost.AppHost.ContentTypeFilters.GetResponseSerializer(contentType);
if (serializer != null)
{
serializer(serializationCtx, errorDto, httpRes);
}
httpRes.EndHttpRequest(skipHeaders: true);
}
示例2: WriteErrorToResponse
public static Task WriteErrorToResponse(this IResponse httpRes, IRequest httpReq,
string contentType, string operationName, string errorMessage, Exception ex, int statusCode)
{
var errorDto = ex.ToErrorResponse();
if (HandleCustomErrorHandler(httpRes, httpReq, contentType, statusCode, errorDto))
return EmptyTask;
if (httpRes.ContentType == null || httpRes.ContentType == MimeTypes.Html)
{
httpRes.ContentType = contentType;
}
if (HostContext.Config.AppendUtf8CharsetOnContentTypes.Contains(contentType))
{
httpRes.ContentType += ContentFormat.Utf8Suffix;
}
httpRes.StatusCode = statusCode;
var serializer = HostContext.ContentTypes.GetResponseSerializer(contentType);
if (serializer != null)
{
serializer(httpReq, errorDto, httpRes);
}
httpRes.EndHttpHandlerRequest(skipHeaders: true);
return EmptyTask;
}
示例3: WriteErrorToResponse
public static Task WriteErrorToResponse(this IResponse httpRes, IRequest httpReq,
string contentType, string operationName, string errorMessage, Exception ex, int statusCode)
{
var errorDto = ex.ToErrorResponse();
HostContext.OnExceptionTypeFilter(ex, errorDto.ResponseStatus);
if (HandleCustomErrorHandler(httpRes, httpReq, contentType, statusCode, errorDto))
return TypeConstants.EmptyTask;
if (httpRes.ContentType == null || httpRes.ContentType == MimeTypes.Html)
{
httpRes.ContentType = contentType;
}
if (HostContext.Config.AppendUtf8CharsetOnContentTypes.Contains(contentType))
{
httpRes.ContentType += ContentFormat.Utf8Suffix;
}
var hold = httpRes.StatusDescription;
var hasDefaultStatusDescription = hold == null || hold == "OK";
httpRes.StatusCode = statusCode;
httpRes.StatusDescription = hasDefaultStatusDescription
? (errorMessage ?? HttpStatus.GetStatusDescription(statusCode))
: hold;
var serializer = HostContext.ContentTypes.GetResponseSerializer(contentType);
if (serializer != null)
{
serializer(httpReq, errorDto, httpRes);
}
httpRes.EndHttpHandlerRequest(skipHeaders: true);
return TypeConstants.EmptyTask;
}
示例4: WriteErrorBody
/// <summary>
/// When HTTP Headers have already been written and only the Body can be written
/// </summary>
public static Task WriteErrorBody(this IResponse httpRes, Exception ex)
{
var req = httpRes.Request;
var errorDto = ex.ToErrorResponse();
HostContext.AppHost.OnExceptionTypeFilter(ex, errorDto.ResponseStatus);
var serializer = HostContext.ContentTypes.GetResponseSerializer(MimeTypes.Html);
serializer?.Invoke(req, errorDto, httpRes);
httpRes.EndHttpHandlerRequest(skipHeaders: true);
return TypeConstants.EmptyTask;
}