From fe2eca4fda72884470c0ff98ba27a52ddc04b071 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Sat, 1 Feb 2020 01:40:50 -0600 Subject: [PATCH] Adding prettier error handling page in the pipeline --- BTCPayServer/Controllers/ErrorController.cs | 18 +++ BTCPayServer/Hosting/Startup.cs | 5 +- BTCPayServer/Views/Error/Handle.cshtml | 19 +++ BTCPayServer/Views/Error/_LayoutError.cshtml | 118 ++++++++++++++++++ BTCPayServer/Views/Error/_ViewStart.cshtml | 3 + .../Views/Shared/_BTCPaySupporters.cshtml | 41 ++++++ .../Views/Shared/_LayoutWelcome.cshtml | 42 +------ 7 files changed, 204 insertions(+), 42 deletions(-) create mode 100644 BTCPayServer/Controllers/ErrorController.cs create mode 100644 BTCPayServer/Views/Error/Handle.cshtml create mode 100644 BTCPayServer/Views/Error/_LayoutError.cshtml create mode 100644 BTCPayServer/Views/Error/_ViewStart.cshtml create mode 100644 BTCPayServer/Views/Shared/_BTCPaySupporters.cshtml diff --git a/BTCPayServer/Controllers/ErrorController.cs b/BTCPayServer/Controllers/ErrorController.cs new file mode 100644 index 000000000..29a02b9e7 --- /dev/null +++ b/BTCPayServer/Controllers/ErrorController.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace BTCPayServer.Controllers +{ + [Route("[controller]/[action]")] + public class ErrorController : Controller + { + public IActionResult Handle(int? statusCode = null) + { + return View(statusCode); + } + } +} diff --git a/BTCPayServer/Hosting/Startup.cs b/BTCPayServer/Hosting/Startup.cs index 541f5cb3f..a88e7f037 100644 --- a/BTCPayServer/Hosting/Startup.cs +++ b/BTCPayServer/Hosting/Startup.cs @@ -241,6 +241,10 @@ namespace BTCPayServer.Hosting forwardingOptions.KnownProxies.Clear(); forwardingOptions.ForwardedHeaders = ForwardedHeaders.All; app.UseForwardedHeaders(forwardingOptions); + + + app.UseStatusCodePagesWithReExecute("/Error/Handle", "?statusCode={0}"); + app.UsePayServer(); app.UseRouting(); app.UseCors(); @@ -252,7 +256,6 @@ namespace BTCPayServer.Hosting app.UseSession(); app.UseWebSockets(); - app.UseStatusCodePages(); app.UseEndpoints(endpoints => { diff --git a/BTCPayServer/Views/Error/Handle.cshtml b/BTCPayServer/Views/Error/Handle.cshtml new file mode 100644 index 000000000..f14d7711a --- /dev/null +++ b/BTCPayServer/Views/Error/Handle.cshtml @@ -0,0 +1,19 @@ +@using System.Net +@model int? +@{ + ViewData["ErrorTitle"] = "Generic Error occurred"; + if (Model.HasValue) + { + var httpCode = (HttpStatusCode)Model.Value; + ViewData["ErrorTitle"] = $"{(int)httpCode} - {httpCode.ToString()}"; + } +} + +

+ Generic error occurred, HTTP Code: @Model +

+ Consult server log for more details. +

+ Navigate back to home. +


+

diff --git a/BTCPayServer/Views/Error/_LayoutError.cshtml b/BTCPayServer/Views/Error/_LayoutError.cshtml new file mode 100644 index 000000000..d208baafc --- /dev/null +++ b/BTCPayServer/Views/Error/_LayoutError.cshtml @@ -0,0 +1,118 @@ +@{ + Layout = null; +} +@inject BTCPayServer.Services.BTCPayServerEnvironment env + + + + + + + + + +
+
+ + +
+
+
+ +

@ViewData["ErrorTitle"]

+
+
+
+
+
+ @RenderBody() +
+
+
+
+
+ @await Html.PartialAsync("_BTCPaySupporters") +
+
+
+
+
+ + diff --git a/BTCPayServer/Views/Error/_ViewStart.cshtml b/BTCPayServer/Views/Error/_ViewStart.cshtml new file mode 100644 index 000000000..5d3510360 --- /dev/null +++ b/BTCPayServer/Views/Error/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_LayoutError"; +} diff --git a/BTCPayServer/Views/Shared/_BTCPaySupporters.cshtml b/BTCPayServer/Views/Shared/_BTCPaySupporters.cshtml new file mode 100644 index 000000000..921df3b12 --- /dev/null +++ b/BTCPayServer/Views/Shared/_BTCPaySupporters.cshtml @@ -0,0 +1,41 @@ +

BTCPayServer Supporters

+ +
+ + Sponsor DG lab + +
+ DG Lab +
+
+
+ + Sponsor ACINQ + +
+ ACINQ +
+
+
+ + Sponsor LunaNode + +
+ LunaNode +
+
+ diff --git a/BTCPayServer/Views/Shared/_LayoutWelcome.cshtml b/BTCPayServer/Views/Shared/_LayoutWelcome.cshtml index c04520c28..0429dc625 100644 --- a/BTCPayServer/Views/Shared/_LayoutWelcome.cshtml +++ b/BTCPayServer/Views/Shared/_LayoutWelcome.cshtml @@ -102,47 +102,7 @@

-

Our supporters

- -
- - Sponsor DG lab - -
- DG Lab -
-
-
- - Sponsor ACINQ - -
- ACINQ -
-
-
- - Sponsor LunaNode - -
- LunaNode -
-
- + @await Html.PartialAsync("_BTCPaySupporters")
@RenderBody()