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;
            };
        }
Exemplo n.º 2
0
        public CoercingPipelines()
        {
            AfterRequest = new AfterPipeline();
            BeforeRequest = new BeforePipeline();
            OnError = new ErrorPipeline();

            OnError += (ctx, ex) => ctx.Response;
        }
Exemplo n.º 3
0
        private static void InvokePreRequestHook(NancyContext context, BeforePipeline pipeline)
        {
            if (pipeline != null)
            {
                var preRequestResponse = pipeline.Invoke(context);

                if (preRequestResponse != null)
                {
                    context.Response = preRequestResponse;
                }
            }
        }
Exemplo n.º 4
0
        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
        {
            BeforePipeline bp = new BeforePipeline();

            // Since we are including the API in the Parking.UI package (because of server constraints)
            // we need to remove the prefix folder so the routes are taken correctly.
            bp.AddItemToStartOfPipeline(ctx => {
                ctx.Request.Url.Path = ctx.Request.Url.Path.Replace("/api", "");
                return ctx.Response;
            });

            pipelines.BeforeRequest += bp;

            // Register gzip compression
            pipelines.RegisterCompressionCheck();

            base.ApplicationStartup(container, pipelines);
        }
Exemplo n.º 5
0
        private static void InvokePreRequestHook(NancyContext context, BeforePipeline pipeline)
        {
            if (pipeline != null)
            {
                var preRequestResponse = pipeline.Invoke(context);

                if (preRequestResponse != null)
                {
                    context.Response = preRequestResponse;
                }
            }
        }
Exemplo n.º 6
0
 private static Task<Response> InvokePreRequestHook(NancyContext context, CancellationToken cancellationToken, BeforePipeline pipeline)
 {
     return pipeline == null ? Task.FromResult<Response>(null) : pipeline.Invoke(context, cancellationToken);
 }
Exemplo n.º 7
0
        private static Task <Response> InvokePreRequestHook(NancyContext context, CancellationToken cancellationToken, BeforePipeline pipeline)
        {
            if (pipeline == null)
            {
                return(TaskHelpers.GetCompletedTask <Response>(null));
            }

            return(pipeline.Invoke(context, cancellationToken));
        }
Exemplo n.º 8
0
 private static Task <Response> InvokePreRequestHook(NancyContext context, CancellationToken cancellationToken, BeforePipeline pipeline)
 {
     return(pipeline == null?Task.FromResult <Response>(null) : pipeline.Invoke(context, cancellationToken));
 }
Exemplo n.º 9
0
        private static Task<Response> InvokePreRequestHook(NancyContext context, CancellationToken cancellationToken, BeforePipeline pipeline)
        {
            if (pipeline == null)
            {
                return TaskHelpers.GetCompletedTask<Response>(null);
            }

            return pipeline.Invoke(context, cancellationToken);
        }