chore: add error handling for 40{3,4} and 500
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b35b3d6ce7
commit
2258ca0f6a
@ -48,5 +48,24 @@ namespace pwt_0x01_ng.Controllers
|
||||
{
|
||||
return View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
|
||||
}
|
||||
|
||||
[Route("/Home/HandleError/{code:int}")]
|
||||
public IActionResult HandleError(int code)
|
||||
{
|
||||
ViewData["ErrorMessage"] = $"Error {code}";
|
||||
switch(code) {
|
||||
case 403:
|
||||
return View("~/Views/Shared/403.cshtml");
|
||||
|
||||
case 404:
|
||||
return View("~/Views/Shared/404.cshtml");
|
||||
|
||||
case 500:
|
||||
return View("~/Views/Shared/500.cshtml");
|
||||
|
||||
default:
|
||||
return View("~/Views/Shared/unhandled_err_code.cshtml");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ namespace pwt_0x01_ng
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
app.UseStatusCodePages();
|
||||
app.UseStatusCodePagesWithReExecute("/Home/HandleError/{0}");
|
||||
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
|
7
Views/Shared/403.cshtml
Normal file
7
Views/Shared/403.cshtml
Normal file
@ -0,0 +1,7 @@
|
||||
@{
|
||||
ViewData["Title"] = "403 Forbidden";
|
||||
}
|
||||
|
||||
<partial name="_errdivtop_part"/>
|
||||
<h2 class="text-secondary">You are not authorized to access the resource.</h2>
|
||||
<partial name="_errdivbottom_part"/>
|
7
Views/Shared/404.cshtml
Normal file
7
Views/Shared/404.cshtml
Normal file
@ -0,0 +1,7 @@
|
||||
@{
|
||||
ViewData["Title"] = "404 Not Found";
|
||||
}
|
||||
|
||||
<partial name="_errdivtop_part"/>
|
||||
<h2 class="text-secondary">The resource you were looking for was not found.</h2>
|
||||
<partial name="_errdivbottom_part"/>
|
7
Views/Shared/500.cshtml
Normal file
7
Views/Shared/500.cshtml
Normal file
@ -0,0 +1,7 @@
|
||||
@{
|
||||
ViewData["Title"] = "500 Internal Server Error";
|
||||
}
|
||||
|
||||
<partial name="_errdivtop_part"/>
|
||||
<h2 class="text-secondary">We apologise, there's been an error on our side.</h2>
|
||||
<partial name="_errdivbottom_part"/>
|
5
Views/Shared/_errdivbottom_part.cshtml
Normal file
5
Views/Shared/_errdivbottom_part.cshtml
Normal file
@ -0,0 +1,5 @@
|
||||
<div class="p-2 mb-2 bg-dark text-white">
|
||||
<h3>Return to<a href="/"> homepage</a></h3>
|
||||
</div>
|
||||
</div> <!-- class="row" -->
|
||||
</div> <!-- class="col-m-1" -->
|
2
Views/Shared/_errdivtop_part.cshtml
Normal file
2
Views/Shared/_errdivtop_part.cshtml
Normal file
@ -0,0 +1,2 @@
|
||||
<div class="row">
|
||||
<div class="col-m-1 text-center bg-dark rounded">
|
7
Views/Shared/unhandled_err_code.cshtml
Normal file
7
Views/Shared/unhandled_err_code.cshtml
Normal file
@ -0,0 +1,7 @@
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<partial name="_errdivtop_part"/>
|
||||
<h2 class="text-secondary">We apologise, an unexpected error occured.</h2>
|
||||
<partial name="_errdivbottom_part"/>
|
Reference in New Issue
Block a user