當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。