本文整理匯總了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());
}