Ejemplo n.º 1
0
 private static void ConfigureStatusCodePagesHandler(IApplicationBuilder app)
 {
     app.UseStatusCodePages(errApp =>
     {
         errApp.Run(async context =>
         {
             await JsonApiResult.Error($"Error: {(HttpStatusCode)context.Response.StatusCode}", context.Response.StatusCode)
             .ExecuteResultAsync(context);
         });
     });
 }
Ejemplo n.º 2
0
        private static void ConfigureExceptionHandler(IApplicationBuilder app)
        {
            app.UseExceptionHandler(appError =>
            {
                appError.Run(async context =>
                {
                    var contextFeature = context.Features.Get <IExceptionHandlerFeature>();

                    if (contextFeature != null)
                    {
                        var exception = contextFeature.Error;

                        await JsonApiResult.Error($"ОШИБКА: {exception?.InnerException?.Message ?? exception?.Message}", 500).ExecuteResultAsync(context);
                    }
                    else
                    {
                        await JsonApiResult.Error("Internal server error.", 500).ExecuteResultAsync(context);
                    }
                });
            });
        }
Ejemplo n.º 3
0
 static JsonApiResult ErrorInvalidInput(ModelStateDictionary model)
 {
     return(JsonApiResult.Error($@"Некорректное тело запроса. Ошибки: {string.Join(", ", GetErrorList(model))}", 415));
 }