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); }); }); }
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); } }); }); }
static JsonApiResult ErrorInvalidInput(ModelStateDictionary model) { return(JsonApiResult.Error($@"Некорректное тело запроса. Ошибки: {string.Join(", ", GetErrorList(model))}", 415)); }