Example #1
0
        public static object ServiceExceptionHandler(IHttpRequest httpReq, object request, Exception ex)
        {
            if (EndpointHost.Config != null && EndpointHost.Config.ReturnsInnerException && ex.InnerException != null && !(ex is IHttpError))
            {
                ex = ex.InnerException;
            }
            ResponseStatus responseStatus = ex.ToResponseStatus();


            if (EndpointHost.DebugMode)
            {
                responseStatus.StackTrace = DtoUtils.GetRequestErrorBody(request) + "\n" + ex;
            }

            var error = DtoUtils.CreateErrorResponse(request, ex, responseStatus);

            IHttpError httpError = error as IHttpError;

            if (httpError != null)
            {
                if (httpReq.QueryString["errorFormat"] == "json")
                {
                    httpError.ContentType = "application/json";
                }
            }

            return(httpError);
        }
Example #2
0
        public static object CreateErrorResponse(this IHttpError httpError)
        {
            if (httpError == null)
            {
                return(null);
            }
            var errorDto = httpError.GetDto();

            if (errorDto != null)
            {
                return(errorDto);
            }

            return(new ErrorResponse {
                ResponseStatus = new ResponseStatus {
                    ErrorCode = httpError.ErrorCode,
                    Message = httpError.Message,
                    StackTrace = httpError.StackTrace,
                }
            });
        }
        public static object ToErrorResponse(this IHttpError httpError)
        {
            if (httpError == null)
            {
                return(null);
            }
            var errorDto = httpError.ToDto();

            if (errorDto != null)
            {
                return(errorDto);
            }

            var error = httpError as HttpError;

            return(new ErrorResponse {
                ResponseStatus = new ResponseStatus {
                    ErrorCode = httpError.ErrorCode,
                    Message = httpError.Message,
                    StackTrace = error != null ? error.StackTrace : null,
                }
            });
        }