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


C# Exception.ToStatusCode方法代码示例

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

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

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

示例4: HandleException

 /// <summary>
 /// Global exception logging
 /// </summary>
 private object HandleException(IResolver iocResolver, object request, Exception ex)
 {
     return new HttpResult(ex.Message, (HttpStatusCode)ex.ToStatusCode());
 }
开发者ID:PaulBD,项目名称:HotelsWeb,代码行数:7,代码来源:Global.asax.cs


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