btcpayserver/BTCPayServer/Controllers/UIErrorController.cs

29 lines
937 B
C#
Raw Normal View History

2020-06-29 04:44:35 +02:00
using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers
{
2022-01-07 04:32:00 +01:00
public class UIErrorController : Controller
{
2022-01-14 04:20:50 +01:00
[Route("/errors/{statusCode:int}")]
public IActionResult Handle(int? statusCode = null)
{
2020-05-01 17:50:04 +02:00
if (Request.Headers.TryGetValue("Accept", out var v) && v.Any(v => v.Contains("text/html", StringComparison.OrdinalIgnoreCase)))
2020-02-01 08:41:27 +01:00
{
2020-05-01 17:50:04 +02:00
if (statusCode.HasValue)
2020-02-01 08:41:27 +01:00
{
2022-01-07 11:46:38 +01:00
var specialPages = new[] { 404, 406, 417, 429, 500, 502, 403 };
2020-05-01 17:50:04 +02:00
if (specialPages.Any(a => a == statusCode.Value))
{
var viewName = statusCode.ToString();
return View(viewName);
}
2020-02-01 08:41:27 +01:00
}
2020-05-01 17:50:04 +02:00
return View(statusCode);
2020-02-01 08:41:27 +01:00
}
2020-05-01 17:50:04 +02:00
return this.StatusCode(statusCode.Value);
}
}
}