本文整理汇总了C#中System.Exception.ToResponseStatus方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.ToResponseStatus方法的具体用法?C# Exception.ToResponseStatus怎么用?C# Exception.ToResponseStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.ToResponseStatus方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogErrorInRedis
private void LogErrorInRedis(string operationName, Exception ex)
{
try
{
//Get a thread-safe redis client from the client manager pool
using (var client = redisManager.GetClient())
{
//Get a client with a native interface for storing 'ResponseStatus' objects
var redis = client.As<ResponseStatus>();
//Store the errors in predictable Redis-named lists i.e.
//'urn:ServiceErrors:{ServiceName}' and 'urn:ServiceErrors:All'
var redisSeriviceErrorList = redis.Lists[UrnId.Create(UrnServiceErrorType, operationName)];
var redisCombinedErrorList = redis.Lists[UrnId.Create(UrnServiceErrorType, CombinedServiceLogId)];
//Append the error at the start of the service-specific and combined error logs.
var responseStatus = ex.ToResponseStatus();
redisSeriviceErrorList.Prepend(responseStatus);
redisCombinedErrorList.Prepend(responseStatus);
//Clip old error logs from the managed logs
const int rollingErrorCount = 1000;
redisSeriviceErrorList.Trim(0, rollingErrorCount);
redisCombinedErrorList.Trim(0, rollingErrorCount);
}
}
catch (Exception suppressRedisException)
{
Log.Error("Could not append exception to redis service error logs", suppressRedisException);
}
}
示例2: HandleMqCustomException
public void HandleMqCustomException(IMessageHandler mqHandler, IMessage<MqCustomException> message, Exception ex)
{
LastCustomException = ex.InnerException as CustomException;
bool requeue = !(ex is UnRetryableMessagingException)
&& message.RetryAttempts < 1;
if (requeue)
{
message.RetryAttempts++;
}
message.Error = ex.ToResponseStatus();
mqHandler.MqClient.Nak(message, requeue: requeue, exception: ex);
}
示例3: HandleException
/// <summary>
///
/// </summary>
/// <param name="iocResolver"></param>
/// <param name="request"></param>
/// <param name="ex"></param>
/// <returns></returns>
public static object HandleException(IResolver iocResolver, object request, Exception ex)
{
if (ex.InnerException != null && !(ex is IHttpError))
ex = ex.InnerException;
var responseStatus = ex.ToResponseStatus();
if (EndpointHost.DebugMode)
{
// View stack trace in tests and on the client
responseStatus.StackTrace = GetRequestErrorBody(request) + ex;
}
Log.Error("ServiceBase<TRequest>::Service Exception", ex);
if (iocResolver != null)
LogErrorInRedisIfExists(iocResolver.TryResolve<IRedisClientsManager>(), request.GetType().Name, responseStatus);
var errorResponse = CreateErrorResponse(request, ex, responseStatus);
return errorResponse;
}
示例4: HandleException
/// <summary>
///
/// </summary>
/// <param name="iocResolver"></param>
/// <param name="request"></param>
/// <param name="ex"></param>
/// <returns></returns>
public static object HandleException(IResolver iocResolver, object request, Exception ex)
{
if (EndpointHost.Config != null && EndpointHost.Config.ReturnsInnerException
&& ex.InnerException != null && !(ex is IHttpError))
{
ex = ex.InnerException;
}
var responseStatus = ex.ToResponseStatus();
if (EndpointHost.DebugMode)
{
// View stack trace in tests and on the client
responseStatus.StackTrace = GetRequestErrorBody(request) + "\n" + ex;
}
Log.Error("ServiceBase<TRequest>::Service Exception", ex);
var errorResponse = CreateErrorResponse(request, ex, responseStatus);
return errorResponse;
}
示例5: WriteEncryptedError
public static void WriteEncryptedError(IRequest req, byte[] cryptKey, byte[] authKey, byte[] iv, Exception ex, string description = null)
{
var error = new ErrorResponse
{
ResponseStatus = ex.ToResponseStatus()
};
var responseBodyBytes = error.ToJson().ToUtf8Bytes();
var encryptedBytes = AesUtils.Encrypt(responseBodyBytes, cryptKey, iv);
var authEncryptedBytes = HmacUtils.Authenticate(encryptedBytes, authKey, iv);
var httpError = ex as IHttpError;
req.Response.StatusCode = (int)HttpStatusCode.BadRequest;
req.Response.StatusDescription = description ?? (httpError != null ? httpError.ErrorCode : ex.GetType().Name);
var errorResponse = new EncryptedMessageResponse
{
EncryptedBody = Convert.ToBase64String(authEncryptedBytes)
};
req.Response.ContentType = MimeTypes.Json;
req.Response.Write(errorResponse.ToJson());
req.Response.EndRequest();
}
示例6: 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();
}
示例7: WriteEncryptedError
public static void WriteEncryptedError(IRequest req, byte[] aesKey, byte[] iv, Exception ex, string description = null)
{
var error = new ErrorResponse {
ResponseStatus = ex.ToResponseStatus()
};
var responseBody = error.ToJson();
var encryptedBody = AesUtils.Encrypt(responseBody, aesKey, iv);
var httpError = ex as IHttpError;
req.Response.StatusCode = (int) HttpStatusCode.BadRequest;
req.Response.StatusDescription = description ?? (httpError != null ? httpError.ErrorCode : ex.GetType().Name);
var errorResponse = new EncryptedMessageResponse
{
EncryptedBody = encryptedBody
};
req.Response.ContentType = MimeTypes.Json;
req.Response.Write(errorResponse.ToJson());
req.Response.EndRequest();
}
示例8: CreateErrorResponse
/// <summary>
///
/// </summary>
/// <param name="iocResolver"></param>
/// <param name="request"></param>
/// <param name="ex"></param>
/// <returns></returns>
public static object CreateErrorResponse(object request, Exception ex)
{
ex = HostContext.AppHost?.ResolveResponseException(ex) ?? ex;
var responseStatus = ex.ToResponseStatus();
if (HostContext.DebugMode)
{
// View stack trace in tests and on the client
responseStatus.StackTrace = GetRequestErrorBody(request) + "\n" + ex;
}
HostContext.AppHost?.OnLogError(typeof(DtoUtils), "ServiceBase<TRequest>::Service Exception", ex);
var errorResponse = CreateErrorResponse(request, ex, responseStatus);
HostContext.AppHost?.OnExceptionTypeFilter(ex, responseStatus);
return errorResponse;
}