Exemplo n.º 1
0
        internal static IApplicationBuilder MapExceptionsToProblems(this IApplicationBuilder app)
        {
            app.UseExceptionHandler(error => error.Run(context =>
            {
                var feature                 = context.Features.Get <IExceptionHandlerFeature>();
                var exceptionHandler        = app.ApplicationServices.GetRequiredService <ExceptionHandler>();
                var(statusCode, problem)    = exceptionHandler.HandleException(feature.Error);
                context.Response.StatusCode = (int)statusCode;

                if (statusCode == HttpStatusCode.InternalServerError)
                {
                    Log.Logger.Error(AlertFactory.UnknownErrorOccured(app.ApplicationServices.GetRequiredService <IMonitorServices>().Info, feature.Error).Serialize());
                }

                if (problem == Problem.Empty)
                {
                    return(context.Response.CompleteAsync());
                }

                context.Response.ContentType = MediaType.JsonProblem;
                return(context.Response.WriteAsync(problem.Serialize()));
            }));

            return(app);
        }
Exemplo n.º 2
0
 public void unexpected_exception_causes_internal_server_error_problem()
 {
     Given(() => an_(unexpected_exception));
     When(handling_a_request);
     Then(it_is_an_internal_error);
     And(() => it_logs(AlertFactory.UnknownErrorOccured(services.GetRequiredService <IMonitorServices>().Info, unexpected_exception)));
 }
Exemplo n.º 3
0
 private void an_unknown_error_alert()
 {
     alert = AlertFactory.UnknownErrorOccured(Fake.AnInstanceMonitor.Info, exception, additional_info);
 }