btcpayserver/BTCPayServer/Controllers/UIErrorController.cs
2022-01-14 13:46:03 +09:00

29 lines
937 B
C#

using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers
{
public class UIErrorController : Controller
{
[Route("/errors/{statusCode:int}")]
public IActionResult Handle(int? statusCode = null)
{
if (Request.Headers.TryGetValue("Accept", out var v) && v.Any(v => v.Contains("text/html", StringComparison.OrdinalIgnoreCase)))
{
if (statusCode.HasValue)
{
var specialPages = new[] { 404, 406, 417, 429, 500, 502, 403 };
if (specialPages.Any(a => a == statusCode.Value))
{
var viewName = statusCode.ToString();
return View(viewName);
}
}
return View(statusCode);
}
return this.StatusCode(statusCode.Value);
}
}
}