本文整理汇总了C#中System.Exception.ToStatusCode方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.ToStatusCode方法的具体用法?C# Exception.ToStatusCode怎么用?C# Exception.ToStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.ToStatusCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateErrorResponse
public static object CreateErrorResponse(object request, Exception ex, ResponseStatus responseStatus)
{
var responseDto = CreateResponseDto(request, responseStatus);
var httpError = ex as IHttpError;
if (httpError != null)
{
if (responseDto != null)
httpError.Response = responseDto;
return httpError;
}
var errorCode = ex.GetType().Name;
var errorMsg = ex.Message;
if (responseStatus != null)
{
errorCode = responseStatus.ErrorCode ?? errorCode;
errorMsg = responseStatus.Message ?? errorMsg;
}
return new HttpError(responseDto, ex.ToStatusCode(), errorCode, errorMsg);
}
示例2: WriteUnencryptedError
// Encrypted Messaging Errors before keys can be extracted have to be written unencrypted
private static void WriteUnencryptedError(IRequest req, Exception ex, string description = null)
{
var errorResponse = new ErrorResponse {
ResponseStatus = ex.ToResponseStatus()
};
var httpError = ex as IHttpError;
req.Response.StatusCode = ex.ToStatusCode();
req.Response.StatusDescription = description ?? (httpError != null ? httpError.ErrorCode : ex.GetType().Name);
req.Response.ContentType = MimeTypes.Json;
req.Response.Write(errorResponse.ToJson());
req.Response.EndRequest();
}
示例3: HandleException
protected void HandleException(string responseContentType, IHttpResponse httpRes, string operationName, Exception ex)
{
var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
Log.Error(errorMessage, ex);
try
{
var statusCode = ex.ToStatusCode();
//httpRes.WriteToResponse always calls .Close in it's finally statement so
//if there is a problem writing to response, by now it will be closed
if (!httpRes.IsClosed)
{
httpRes.WriteErrorToResponse(responseContentType, operationName, errorMessage, ex, statusCode);
}
}
catch (Exception writeErrorEx)
{
//Exception in writing to response should not hide the original exception
Log.Info("Failed to write error to response: {0}", writeErrorEx);
//rethrow the original exception
throw ex;
}
finally
{
httpRes.EndServiceStackRequest(skipHeaders: true);
}
}
示例4: HandleException
/// <summary>
/// Global exception logging
/// </summary>
private object HandleException(IResolver iocResolver, object request, Exception ex)
{
return new HttpResult(ex.Message, (HttpStatusCode)ex.ToStatusCode());
}