public ErrorHandlingPipelines(IResponseNegotiator responseNegotiator, INancyErrorMap errorMap)
        {
            this.responseNegotiator = responseNegotiator;
            this.errorMap = errorMap;

            AfterRequest = new AfterPipeline();
            BeforeRequest = new BeforePipeline();
            OnError = new ErrorPipeline();

            OnError += (ctx, ex) =>
            {
                var nonAggregateException = ex.TrimAggregateException();

                if (!errorMap.Contains(nonAggregateException.GetType()))
                {
                    Logger.DebugFormat("Exception type not found in ErrorMap. Exception: {0}", nonAggregateException.GetType());

                    ctx.Response = DefaultError(ctx);
                }
                else
                {
                    ctx.Response = Error(nonAggregateException, ctx);
                }

                return null;
            };
        }
Пример #2
0
 public PipelinesBuilder WithErrorHandling(IResponseNegotiator responseNegotiator, INancyErrorMap errorMap)
 {
     this.pipelinesDictionary.Add(1, () => new ErrorHandlingPipelines(responseNegotiator, errorMap));
     return this;
 }