mirror of https://github.com/abpframework/abp.git
7 changed files with 103 additions and 2 deletions
@ -0,0 +1,39 @@ |
|||||
|
@page |
||||
|
@using Localization.Resources.AbpUi |
||||
|
@using Microsoft.AspNetCore.Mvc.Localization |
||||
|
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Pages.Error |
||||
|
@model IndexModel |
||||
|
@inject IHtmlLocalizer<AbpUiResource> L |
||||
|
@{ |
||||
|
var errorMessage = Model.ErrorInfo.Message; |
||||
|
var errorDetails = Model.ErrorInfo.Details; |
||||
|
if (errorDetails.IsNullOrEmpty()) |
||||
|
{ |
||||
|
errorDetails = errorMessage; |
||||
|
errorMessage = L["Error"].Value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
<h1> |
||||
|
[@Model.HttpStatusCode] @errorMessage |
||||
|
</h1> |
||||
|
|
||||
|
<div> |
||||
|
<p> |
||||
|
@errorDetails |
||||
|
</p> |
||||
|
<p> |
||||
|
@if (!Model.ErrorInfo.ValidationErrors.IsNullOrEmpty()) |
||||
|
{ |
||||
|
foreach (var validationError in Model.ErrorInfo.ValidationErrors) |
||||
|
{ |
||||
|
<text>* </text>@(validationError.Message) |
||||
|
if (validationError.Members != null && validationError.Members.Any()) |
||||
|
{ |
||||
|
<text>(@string.Join(", ", validationError.Members))</text> |
||||
|
} |
||||
|
<br /> |
||||
|
} |
||||
|
} |
||||
|
</p> |
||||
|
</div> |
||||
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNetCore.Diagnostics; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.AspNetCore.Mvc.RazorPages; |
||||
|
using Volo.Abp.AspNetCore.Mvc.ExceptionHandling; |
||||
|
using Volo.Abp.Http; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Pages.Error |
||||
|
{ |
||||
|
public class IndexModel : PageModel |
||||
|
{ |
||||
|
public RemoteServiceErrorInfo ErrorInfo { get; set; } |
||||
|
|
||||
|
[BindProperty(SupportsGet = true)] |
||||
|
public int HttpStatusCode { get; set; } |
||||
|
|
||||
|
private readonly IExceptionToErrorInfoConverter _errorInfoConverter; |
||||
|
|
||||
|
public IndexModel(IExceptionToErrorInfoConverter errorInfoConverter) |
||||
|
{ |
||||
|
_errorInfoConverter = errorInfoConverter; |
||||
|
} |
||||
|
|
||||
|
public void OnGet() |
||||
|
{ |
||||
|
var exHandlerFeature = HttpContext.Features.Get<IExceptionHandlerFeature>(); |
||||
|
|
||||
|
var exception = exHandlerFeature != null |
||||
|
? exHandlerFeature.Error |
||||
|
: new Exception("Unhandled exception!"); //TODO: Localize?
|
||||
|
|
||||
|
ErrorInfo = _errorInfoConverter.Convert(exception); |
||||
|
|
||||
|
if (HttpStatusCode == 0) |
||||
|
{ |
||||
|
HttpStatusCode = HttpContext.Response.StatusCode; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared |
||||
|
{ |
||||
|
public static class AbpApplicationBuilderErrorPageExtensions |
||||
|
{ |
||||
|
public static IApplicationBuilder UseErrorPage(this IApplicationBuilder app) |
||||
|
{ |
||||
|
return app |
||||
|
.UseStatusCodePagesWithRedirects("~/Error?httpStatusCode={0}") |
||||
|
.UseExceptionHandler("/Error"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue