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