Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Identity service error controller to account module #5085

Merged
merged 6 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Net;
using System.Threading.Tasks;
using AutoMapper.Internal;
using IdentityServer4.Models;
using IdentityServer4.Services;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Views.Error;
using Volo.Abp.Http;

namespace Volo.Abp.Account.Web.Areas.Account.Controllers
{
[Area("account")]
public class ErrorController : AbpController
{
private readonly IIdentityServerInteractionService _interaction;
private readonly IWebHostEnvironment _environment;
private readonly AbpErrorPageOptions _abpErrorPageOptions;

public ErrorController(
IIdentityServerInteractionService interaction,
IWebHostEnvironment environment,
IOptions<AbpErrorPageOptions> abpErrorPageOptions)
{
_interaction = interaction;
_environment = environment;
_abpErrorPageOptions = abpErrorPageOptions.Value;
}

public async Task<IActionResult> Index(string errorId)
realLiangshiwei marked this conversation as resolved.
Show resolved Hide resolved
{
var errorMessage = await _interaction.GetErrorContextAsync(errorId) ?? new ErrorMessage
{
Error = L["Error"]
};

if (!_environment.IsDevelopment())
{
// Only show in development
errorMessage.ErrorDescription = null;
}

const int statusCode = (int)HttpStatusCode.InternalServerError;

return View(GetErrorPageUrl(statusCode), new AbpErrorViewModel
{
ErrorInfo = new RemoteServiceErrorInfo(errorMessage.Error, errorMessage.ErrorDescription),
HttpStatusCode = statusCode
});
}

private string GetErrorPageUrl(int statusCode)
realLiangshiwei marked this conversation as resolved.
Show resolved Hide resolved
{
var page = _abpErrorPageOptions.ErrorViewUrls.GetOrDefault(statusCode.ToString());

return string.IsNullOrWhiteSpace(page) ? "~/Views/Error/Default.cshtml" : page;
}
}
}

This file was deleted.

This file was deleted.