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;
            };
        }
        public CoercingPipelines()
        {
            AfterRequest = new AfterPipeline();
            BeforeRequest = new BeforePipeline();
            OnError = new ErrorPipeline();

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

                if (preRequestResponse != null)
                {
                    context.Response = preRequestResponse;
                }
            }
        }
Beispiel #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);
        }
Beispiel #5
0
        private static void InvokePreRequestHook(NancyContext context, BeforePipeline pipeline)
        {
            if (pipeline != null)
            {
                var preRequestResponse = pipeline.Invoke(context);

                if (preRequestResponse != null)
                {
                    context.Response = preRequestResponse;
                }
            }
        }
Beispiel #6
0
 private static Task<Response> InvokePreRequestHook(NancyContext context, CancellationToken cancellationToken, BeforePipeline pipeline)
 {
     return pipeline == null ? Task.FromResult<Response>(null) : pipeline.Invoke(context, cancellationToken);
 }
Beispiel #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));
        }
Beispiel #8
0
 private static Task <Response> InvokePreRequestHook(NancyContext context, CancellationToken cancellationToken, BeforePipeline pipeline)
 {
     return(pipeline == null?Task.FromResult <Response>(null) : pipeline.Invoke(context, cancellationToken));
 }
Beispiel #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);
        }