Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(options =>
                {
                    options.SwaggerEndpoint("/swagger/v1/swagger.json", "Haru ga Kita!");
                });
            }
            else
            {
                app.UseHsts();
            }

            app.UseAuthentication();
            app.UseExceptionHandler(error =>
            {
                error.Run(async context =>
                {
                    await Task.Run(() =>
                    {
                        var apiErrorHandler = new ApiErrorHandler(context);
                        apiErrorHandler.Handle();
                    });
                });
            });
            app.UseMvc();
        }
        public override void OnException(ExceptionContext context)
        {
            ApiError apiError = null;

            // Handle Errors thru the chain
            ErrorHandler apiErrorHanler           = new ApiErrorHandler();
            ErrorHandler unauthorizedErrorHandler = new UnauthorizedErrorHandler();
            ErrorHandler unhandledErrorHandler    = new UnhandledErrorHandler();

            // Set Handlers
            apiErrorHanler.SetNextHandler(unauthorizedErrorHandler);
            unauthorizedErrorHandler.SetNextHandler(unhandledErrorHandler);

            // Hanle
            apiErrorHanler.Handle(context, apiError);

            base.OnException(context);
        }