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


C# Exception.ToErrorResponse方法代码示例

本文整理汇总了C#中System.Exception.ToErrorResponse方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.ToErrorResponse方法的具体用法?C# Exception.ToErrorResponse怎么用?C# Exception.ToErrorResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Exception的用法示例。


在下文中一共展示了Exception.ToErrorResponse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteErrorToResponse

        public static void WriteErrorToResponse(this IHttpResponse httpRes, IHttpRequest httpReq,
            string contentType, string operationName, string errorMessage, Exception ex, int statusCode)
        {
            var errorDto = ex.ToErrorResponse();
            if (HandleCustomErrorHandler(httpRes, httpReq, contentType, statusCode, errorDto)) return;

            if (httpRes.ContentType == null || httpRes.ContentType == ContentType.Html)
            {
                httpRes.ContentType = contentType;
            }
            if (EndpointHost.Config.AppendUtf8CharsetOnContentTypes.Contains(contentType))
            {
                httpRes.ContentType += ContentType.Utf8Suffix;
            }

            httpRes.StatusCode = statusCode;
            var serializationCtx = new SerializationContext(contentType);

            var serializer = EndpointHost.AppHost.ContentTypeFilters.GetResponseSerializer(contentType);
            if (serializer != null)
            {
                serializer(serializationCtx, errorDto, httpRes);
            }
            
            httpRes.EndHttpRequest(skipHeaders: true);
        }
开发者ID:h2oman,项目名称:ServiceStack,代码行数:26,代码来源:IHttpResponseExtensions.cs

示例2: WriteErrorToResponse

        public static Task WriteErrorToResponse(this IResponse httpRes, IRequest httpReq,
            string contentType, string operationName, string errorMessage, Exception ex, int statusCode)
        {
            var errorDto = ex.ToErrorResponse();
            if (HandleCustomErrorHandler(httpRes, httpReq, contentType, statusCode, errorDto)) 
                return EmptyTask;

            if (httpRes.ContentType == null || httpRes.ContentType == MimeTypes.Html)
            {
                httpRes.ContentType = contentType;
            }
            if (HostContext.Config.AppendUtf8CharsetOnContentTypes.Contains(contentType))
            {
                httpRes.ContentType += ContentFormat.Utf8Suffix;
            }

            httpRes.StatusCode = statusCode;
            var serializer = HostContext.ContentTypes.GetResponseSerializer(contentType);
            if (serializer != null)
            {
                serializer(httpReq, errorDto, httpRes);
            }
            
            httpRes.EndHttpHandlerRequest(skipHeaders: true);

            return EmptyTask;
        }
开发者ID:serra,项目名称:ServiceStack,代码行数:27,代码来源:HttpResponseExtensionsInternal.cs

示例3: WriteErrorToResponse

        public static Task WriteErrorToResponse(this IResponse httpRes, IRequest httpReq,
            string contentType, string operationName, string errorMessage, Exception ex, int statusCode)
        {
            var errorDto = ex.ToErrorResponse();
            HostContext.OnExceptionTypeFilter(ex, errorDto.ResponseStatus);

            if (HandleCustomErrorHandler(httpRes, httpReq, contentType, statusCode, errorDto))
                return TypeConstants.EmptyTask;

            if (httpRes.ContentType == null || httpRes.ContentType == MimeTypes.Html)
            {
                httpRes.ContentType = contentType;
            }
            if (HostContext.Config.AppendUtf8CharsetOnContentTypes.Contains(contentType))
            {
                httpRes.ContentType += ContentFormat.Utf8Suffix;
            }

            var hold = httpRes.StatusDescription;
            var hasDefaultStatusDescription = hold == null || hold == "OK";

            httpRes.StatusCode = statusCode;

            httpRes.StatusDescription = hasDefaultStatusDescription
                ? (errorMessage ?? HttpStatus.GetStatusDescription(statusCode))
                : hold;

            var serializer = HostContext.ContentTypes.GetResponseSerializer(contentType);
            if (serializer != null)
            {
                serializer(httpReq, errorDto, httpRes);
            }

            httpRes.EndHttpHandlerRequest(skipHeaders: true);

            return TypeConstants.EmptyTask;
        }
开发者ID:charygao,项目名称:ServiceStack,代码行数:37,代码来源:HttpResponseExtensionsInternal.cs

示例4: WriteErrorBody

 /// <summary>
 /// When HTTP Headers have already been written and only the Body can be written
 /// </summary>
 public static Task WriteErrorBody(this IResponse httpRes, Exception ex)
 {
     var req = httpRes.Request;
     var errorDto = ex.ToErrorResponse();
     HostContext.AppHost.OnExceptionTypeFilter(ex, errorDto.ResponseStatus);
     var serializer = HostContext.ContentTypes.GetResponseSerializer(MimeTypes.Html);
     serializer?.Invoke(req, errorDto, httpRes);
     httpRes.EndHttpHandlerRequest(skipHeaders: true);
     return TypeConstants.EmptyTask;
 }
开发者ID:ServiceStack,项目名称:ServiceStack,代码行数:13,代码来源:HttpResponseExtensionsInternal.cs


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