当前位置: 首页>>代码示例>>C#>>正文


C# Exception.ToResponseStatus方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:31,代码来源:RedisErrorLoggerFeature.cs

示例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);
        }
开发者ID:jin29neci,项目名称:ServiceStack,代码行数:15,代码来源:MqAppHostTests.cs

示例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;
        }
开发者ID:grammarware,项目名称:fodder,代码行数:29,代码来源:src_ServiceStack_ServiceHost_DtoUtils.cs

示例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;
        }
开发者ID:jmaucher,项目名称:SStack,代码行数:29,代码来源:DtoUtils.cs

示例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();
        }
开发者ID:rudygt,项目名称:ServiceStack,代码行数:25,代码来源:EncryptedMessagesFeature.cs

示例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();
        }
开发者ID:rudygt,项目名称:ServiceStack,代码行数:15,代码来源:EncryptedMessagesFeature.cs

示例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();
        }
开发者ID:AimaTeam-hehai,项目名称:ServiceStack,代码行数:23,代码来源:EncryptedMessagesFeature.cs

示例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;
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:26,代码来源:DtoUtils.cs


注:本文中的System.Exception.ToResponseStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。