コード例 #1
0
        private static Response CreateNegotiatedResponse(NancyContext context, IResponseNegotiator responseNegotiator, Exception exception, HttpServiceError defaultError)
        {
            HttpServiceError httpServiceError = ExtractFromException(exception, defaultError);

            Negotiator negotiator = new Negotiator(context)
                .WithServiceError(httpServiceError);

            return responseNegotiator.NegotiateResponse(negotiator, context);
        }
コード例 #2
0
        private static HttpServiceError ExtractFromException(Exception exception, HttpServiceError defaultValue)
        {
            HttpServiceError result = defaultValue;

            if (exception != null)
            {
                HttpServiceErrorException exceptionWithServiceError = exception as HttpServiceErrorException;

                if (exceptionWithServiceError != null)
                {
                    result = exceptionWithServiceError.HttpServiceError;
                }
            }

            return result;
        }
コード例 #3
0
        public static void Enable(IPipelines pipelines, IResponseNegotiator responseNegotiator, HttpServiceError defaultError)
        {
            if (pipelines == null)
            {
                throw new ArgumentNullException("pipelines");
            }

            if (responseNegotiator == null)
            {
                throw new ArgumentNullException("responseNegotiator");
            }

            if (defaultError == null)
            {
                throw new ArgumentNullException("defaultError");
            }

            pipelines.OnError += (context, exception) => HandleException(context, exception, responseNegotiator, defaultError);
        }
コード例 #4
0
        private static Response HandleException(NancyContext context, Exception exception, IResponseNegotiator responseNegotiator, HttpServiceError defaultError)
        {
            LogException(context, exception);

            return CreateNegotiatedResponse(context, responseNegotiator, exception, defaultError);
        }
コード例 #5
0
 public static Negotiator WithServiceError(this Negotiator negotiator, HttpServiceError httpServiceError)
 {
     return negotiator
         .WithStatusCode(httpServiceError.HttpStatusCode)
         .WithModel(httpServiceError.ServiceError);
 }