From cb9119ac58038ae10c9e8a6f5c4103708d2a6975 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 23 Oct 2019 13:35:20 -0500 Subject: [PATCH] add more informative 404 errors --- SharedLibraryCore/Services/ClientService.cs | 5 +++++ WebfrontCore/Controllers/HomeController.cs | 7 ++++++- WebfrontCore/Startup.cs | 2 ++ WebfrontCore/Views/Shared/Error.cshtml | 11 ++++++++++- WebfrontCore/Views/Shared/ResponseStatusCode.cshtml | 13 +++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 WebfrontCore/Views/Shared/ResponseStatusCode.cshtml diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index f357ef2ad..795294dfa 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -299,6 +299,11 @@ namespace SharedLibraryCore.Services var client = await iqClient.FirstOrDefaultAsync(); + if (client == null) + { + return null; + } + var foundClient = new { Client = client, diff --git a/WebfrontCore/Controllers/HomeController.cs b/WebfrontCore/Controllers/HomeController.cs index c351122dc..b56cb2fdb 100644 --- a/WebfrontCore/Controllers/HomeController.cs +++ b/WebfrontCore/Controllers/HomeController.cs @@ -34,7 +34,12 @@ namespace WebfrontCore.Controllers ViewBag.Description = Localization["WEBFRONT_ERROR_DESC"]; ViewBag.Title = Localization["WEBFRONT_ERROR_TITLE"]; - return View(); + return View(exceptionFeature.Error); + } + + public IActionResult ResponseStatusCode(int? statusCode = null) + { + return View(statusCode); } } } diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index 61eeec9c4..304ed0c64 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -92,6 +92,8 @@ namespace WebfrontCore // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { + app.UseStatusCodePagesWithRedirects("/Home/ResponseStatusCode?statusCode={0}"); + if (env.EnvironmentName == "Development") { app.UseDeveloperExceptionPage(); diff --git a/WebfrontCore/Views/Shared/Error.cshtml b/WebfrontCore/Views/Shared/Error.cshtml index 6fac1a571..95c2db318 100644 --- a/WebfrontCore/Views/Shared/Error.cshtml +++ b/WebfrontCore/Views/Shared/Error.cshtml @@ -1,6 +1,15 @@ -@{ +@model Exception +@using SharedLibraryCore + +@{ ViewData["Title"] = "Error"; }

@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_GENERIC_TITLE"]

@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_GENERIC_DESC"]

+ + @if (Model != null) + { + @SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_CODE"].FormatExt(Model.Message); + } + diff --git a/WebfrontCore/Views/Shared/ResponseStatusCode.cshtml b/WebfrontCore/Views/Shared/ResponseStatusCode.cshtml new file mode 100644 index 000000000..384a43601 --- /dev/null +++ b/WebfrontCore/Views/Shared/ResponseStatusCode.cshtml @@ -0,0 +1,13 @@ +@model int +@{ + ViewData["Title"] = "Error"; +} + +

@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_GENERIC_TITLE"]

+

@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_GENERIC_DESC"]

+ + @if (Model == 404) + { + @SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_ERROR_NOTFOUND"] + } + \ No newline at end of file