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
        private static void InvokeOnErrorHook(Context context, ErrorPipeline pipeline, Exception errorException)
        {
            try
            {
                if (pipeline == null)
                {
                    throw new RequestPipelinesException(errorException);
                }

                var onErrorResult = pipeline.Invoke(context, errorException);

                if (onErrorResult == null)
                {
                    throw new RequestPipelinesException(errorException);
                }

                context.Response = new Response {
                    StatusCode = HttpStatusCode.InternalServerError
                };
            }
            catch (Exception)
            {
                context.Response = new Response {
                    StatusCode = HttpStatusCode.InternalServerError
                };
            }
        }
Пример #3
0
        public void Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines()
        {
            // Given
            var item1Called = false;
            Func <NancyContext, Exception, Response> item1 = (ctx, ex) => { item1Called = true; return(null); };
            var item2Called = false;
            Func <NancyContext, Exception, Response> item2 = (ctx, ex) => { item2Called = true; return(null); };
            var item3Called = false;
            Func <NancyContext, Exception, Response> item3 = (ctx, ex) => { item3Called = true; return(null); };
            var item4Called = false;
            Func <NancyContext, Exception, Response> item4 = (ctx, ex) => { item4Called = true; return(null); };

            pipeline += item1;
            pipeline += item2;
            var subPipeline = new ErrorPipeline();

            subPipeline += item3;
            subPipeline += item4;

            // When
            pipeline.AddItemToEndOfPipeline(subPipeline);
            pipeline.Invoke(CreateContext(), new Exception());

            // Then
            item1Called.ShouldBeTrue();
            item2Called.ShouldBeTrue();
            item3Called.ShouldBeTrue();
            item4Called.ShouldBeTrue();
        }
Пример #4
0
        public void Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines()
        {
            // Given
            var item1Called = false;
            Func<NancyContext, Exception, dynamic> item1 = (ctx, ex) => { item1Called = true; return null; };
            var item2Called = false;
            Func<NancyContext, Exception, dynamic> item2 = (ctx, ex) => { item2Called = true; return null; };
            var item3Called = false;
            Func<NancyContext, Exception, dynamic> item3 = (ctx, ex) => { item3Called = true; return null; };
            var item4Called = false;
            Func<NancyContext, Exception, dynamic> item4 = (ctx, ex) => { item4Called = true; return null; };
            pipeline += item1;
            pipeline += item2;
            var subPipeline = new ErrorPipeline();
            subPipeline += item3;
            subPipeline += item4;

            // When
            pipeline.AddItemToEndOfPipeline(subPipeline);
            pipeline.Invoke(CreateContext(), new Exception());

            // Then
            item1Called.ShouldBeTrue();
            item2Called.ShouldBeTrue();
            item3Called.ShouldBeTrue();
            item4Called.ShouldBeTrue();
        }
Пример #5
0
        public CoercingPipelines()
        {
            AfterRequest = new AfterPipeline();
            BeforeRequest = new BeforePipeline();
            OnError = new ErrorPipeline();

            OnError += (ctx, ex) => ctx.Response;
        }
Пример #6
0
        public void PlusEquals_with_func_adds_item_to_end_of_pipeline()
        {
            // Given, When
            pipeline += (ctx, ex) => null;
            pipeline += (ctx, ex) => null;

            // Then
            pipeline.PipelineDelegates.ShouldHaveCount(2);
        }
Пример #7
0
        public void PlusEquals_with_func_adds_item_to_end_of_pipeline()
        {
            // Given, When
            pipeline += (ctx, ex) => null;
            pipeline += (ctx, ex) => null;

            // Then
            pipeline.PipelineDelegates.ShouldHaveCount(2);
        }
Пример #8
0
        public void When_cast_from_func_creates_a_pipeline_with_one_item()
        {
            // Given
            var castPipeline = new ErrorPipeline();
            
            // When
            castPipeline += (ctx, ex) => null;

            // Then
            castPipeline.PipelineDelegates.ShouldHaveCount(1);
        }
Пример #9
0
        public void When_cast_from_func_creates_a_pipeline_with_one_item()
        {
            // Given
            var castPipeline = new ErrorPipeline();

            // When
            castPipeline += (ctx, ex) => null;

            // Then
            castPipeline.PipelineDelegates.ShouldHaveCount(1);
        }
Пример #10
0
    void OnLoginFail(SocketIOEvent evt)
    {
        var msg = string.Empty;

        evt.data.GetField(ref msg, "message");
        var error = msg.Split(':');

        if (error.Length > 1)
        {
            loginFailMessage = error[1];
        }

        ErrorPipeline.FireError(error[0]);
    }
Пример #11
0
        public void PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline()
        {
            // Given
            pipeline.AddItemToEndOfPipeline((ctx, ex) => null);
            pipeline.AddItemToEndOfPipeline((ctx, ex) => null);
            var pipeline2 = new ErrorPipeline();
            pipeline2.AddItemToEndOfPipeline((ctx, ex) => null);
            pipeline2.AddItemToEndOfPipeline((ctx, ex) => null);

            // When
            pipeline += pipeline2;

            // Then
            pipeline.PipelineItems.ShouldHaveCount(4);
            pipeline2.PipelineDelegates.ElementAt(0).ShouldBeSameAs(pipeline.PipelineDelegates.ElementAt(2));
            pipeline2.PipelineDelegates.ElementAt(1).ShouldBeSameAs(pipeline.PipelineDelegates.Last());
        }
Пример #12
0
        public void PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline()
        {
            // Given
            pipeline.AddItemToEndOfPipeline((ctx, ex) => null);
            pipeline.AddItemToEndOfPipeline((ctx, ex) => null);
            var pipeline2 = new ErrorPipeline();

            pipeline2.AddItemToEndOfPipeline((ctx, ex) => null);
            pipeline2.AddItemToEndOfPipeline((ctx, ex) => null);

            // When
            pipeline += pipeline2;

            // Then
            pipeline.PipelineItems.ShouldHaveCount(4);
            pipeline2.PipelineDelegates.ElementAt(0).ShouldBeSameAs(pipeline.PipelineDelegates.ElementAt(2));
            pipeline2.PipelineDelegates.ElementAt(1).ShouldBeSameAs(pipeline.PipelineDelegates.Last());
        }
        public ExceptionlessMqServer(IRedisClientsManager clientsManager, IProjectRepository projectRepository, IUserRepository userRepository,
            IErrorStackRepository stackRepository, IOrganizationRepository organizationRepository, ErrorPipeline errorPipeline,
            ErrorStatsHelper errorStatsHelper, IProjectHookRepository projectHookRepository, ICacheClient cacheClient, IMailer mailer, IAppStatsClient stats)
            : base(clientsManager) {
            _projectRepository = projectRepository;
            _projectHookRepository = projectHookRepository;
            _userRepository = userRepository;
            _stackRepository = stackRepository;
            _organizationRepository = organizationRepository;
            _errorPipeline = errorPipeline;
            _errorStatsHelper = errorStatsHelper;
            _cacheClient = cacheClient;
            _mailer = mailer;
            _stats = stats;

            RegisterHandler<SummaryNotification>(ProcessSummaryNotification, ProcessSummaryNotificationException);
            RegisterHandler<ErrorNotification>(ProcessNotification, ProcessNotificationException);
            RegisterHandler<Error>(ProcessError, ProcessErrorException);
            RegisterHandler<WebHookNotification>(ProcessWebHookNotification, ProcessWebHookNotificationException);
        }
Пример #14
0
        public ExceptionlessMqServer(IRedisClientsManager clientsManager, IProjectRepository projectRepository, IUserRepository userRepository,
                                     IErrorStackRepository stackRepository, IOrganizationRepository organizationRepository, ErrorPipeline errorPipeline,
                                     ErrorStatsHelper errorStatsHelper, IProjectHookRepository projectHookRepository, ICacheClient cacheClient, IMailer mailer, IAppStatsClient stats)
            : base(clientsManager)
        {
            _projectRepository      = projectRepository;
            _projectHookRepository  = projectHookRepository;
            _userRepository         = userRepository;
            _stackRepository        = stackRepository;
            _organizationRepository = organizationRepository;
            _errorPipeline          = errorPipeline;
            _errorStatsHelper       = errorStatsHelper;
            _cacheClient            = cacheClient;
            _mailer = mailer;
            _stats  = stats;

            RegisterHandler <SummaryNotification>(ProcessSummaryNotification, ProcessSummaryNotificationException);
            RegisterHandler <ErrorNotification>(ProcessNotification, ProcessNotificationException);
            RegisterHandler <Error>(ProcessError, ProcessErrorException);
            RegisterHandler <WebHookNotification>(ProcessWebHookNotification, ProcessWebHookNotificationException);
        }
Пример #15
0
        protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
        {
            // Identify request holder through API key
            var configuration = new StatelessAuthenticationConfiguration(ctx =>
            {
                Guid apiKey;

                // If API key found, retrieve user information associated with the
                // API key. If user found, add user information to request
                if (Guid.TryParse(ctx.Request.Headers.Authorization, out apiKey))
                {
                    var query            = container.Resolve <IUserHelper>();
                    ClaimsPrincipal user = query.GetBy(apiKey);

                    if (user.Identity.Name == string.Empty)
                    {
                        return(null);
                    }

                    // Add user information
                    ctx.Items.Add(new KeyValuePair <string, object>("user", user.Identity));
                    container.Resolve <IHttpContextAccessor>().HttpContext.User = user;
                    return(user);
                }

                return(null);
            });

            // Add a default error handler to pipeline
            ErrorPipeline er = new ErrorPipeline();

            er.AddItemToEndOfPipeline((ctx, ex) => LogAndGetErrorResponse(ex, ctx));

            pipelines.OnError = er;
            StatelessAuthentication.Enable(pipelines, configuration);
        }
Пример #16
0
 private void Awake()
 {
     ErrorPipeline.LogToError("LFNEX", () => { LaunchErrorMesssage(loginFailMessage); });
     ErrorPipeline.LogToError("LFWP", () => { LaunchErrorMesssage(loginFailMessage); });
     ErrorPipeline.LogToError("ACFAE", () => { LaunchErrorMesssage(loginFailMessage); });
 }
 public void SetUp()
 {
     _sut = ErrorPipelines.HandleRequestValidationException();
 }
Пример #18
0
 public ErrorPipelineFixture()
 {
     pipeline = new ErrorPipeline();
 }
Пример #19
0
 public MockApplicationPipelines()
 {
     this.BeforeRequest = new BeforePipeline();
     this.AfterRequest  = new AfterPipeline();
     this.OnError       = new ErrorPipeline();
 }
Пример #20
0
 public MockPipelines()
 {
     this.BeforeRequest = new BeforePipeline();
     this.AfterRequest = new AfterPipeline();
     this.OnError = new ErrorPipeline();
 }
Пример #21
0
 public FakePipelines()
 {
     BeforeRequest = new BeforePipeline();
     AfterRequest  = new AfterPipeline();
     OnError       = new ErrorPipeline();
 }
 public void SetUp()
 {
     _sut = ErrorPipelines.HandleModelBindingException();
 }
Пример #23
0
 public ErrorPipelineFixture()
 {
     pipeline = new ErrorPipeline();
 }
 public void SetUp()
 {
     _sut = ErrorPipelines.HandleModelBindingException();
 }
 public void SetUp()
 {
     _sut = ErrorPipelines.HandleRequestValidationException();
 }
 public void SetUp()
 {
     _sut = ErrorPipelines.HandleSecurityException();
 }
Пример #27
0
        private static void InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)
        {
            try
            {
                if (pipeline == null)
                {
                    throw new RequestExecutionException(ex);
                }

                var onErrorResponse = pipeline.Invoke(context, ex);

                if (onErrorResponse == null)
                {
                    throw new RequestExecutionException(ex);
                }

                context.Response = onErrorResponse;
            }
            catch (Exception e)
            {
                context.Response = new Response { StatusCode = HttpStatusCode.InternalServerError };
                context.Items[ERROR_KEY] = e.ToString();
                context.Items[ERROR_EXCEPTION] = e;
            }
        }
 public void SetUp()
 {
     _sut = ErrorPipelines.HandleSecurityException();
 }