diff --git a/KamihamaWeb/Controllers/ErrorController.cs b/KamihamaWeb/Controllers/ErrorController.cs new file mode 100644 index 0000000..13ee8e0 --- /dev/null +++ b/KamihamaWeb/Controllers/ErrorController.cs @@ -0,0 +1,53 @@ +using KamihamaWeb.Models; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Diagnostics; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace KamihamaWeb.Controllers +{ + public class ErrorController : Controller + { + [Route("Error/{statusCode}")] + [AllowAnonymous] + public IActionResult HttpStatusCodeHandler(int statusCode) + { + var feature = HttpContext.Features.Get(); + var path = feature?.OriginalPath; + if (!string.IsNullOrEmpty(path)) + { + if (path.StartsWith("/api/v1")) + { + switch (statusCode) + { + case 404: + return new APIResult(404, "not found"); + case 503: + return new APIResult(503, "service temporarily unavailable"); + default: + return new APIResult(500, "an error has occurred"); + } + + } + } + switch (statusCode) + { + case 404: + ViewBag.Title = "404 Not Found"; + ViewData["ErrorMessage"] = "The resource you requested could not be found."; + break; + case 503: + ViewBag.Title = "503 Service Unavailable"; + ViewData["ErrorMessage"] = "The requested resource is currently unavailable."; + break; + default: + ViewBag.Title = "Unknown Error"; + ViewData["ErrorMessage"] = "An unknown error occurred."; + break; + } + + return View("HttpError"); + } + } +} +} \ No newline at end of file diff --git a/KamihamaWeb/Controllers/ResourceController.cs b/KamihamaWeb/Controllers/ResourceController.cs index 1ea5a17..004ee32 100644 --- a/KamihamaWeb/Controllers/ResourceController.cs +++ b/KamihamaWeb/Controllers/ResourceController.cs @@ -71,6 +71,7 @@ namespace KamihamaWeb.Controllers [Route("resource/{*url}")] [HttpGet] + [HttpCacheExpiration(MaxAge = 60*60*24)] public async Task GetAsset(string url) { /*WebClient wc = new WebClient(); diff --git a/KamihamaWeb/Views/Home/Index.cshtml b/KamihamaWeb/Views/Home/Index.cshtml index d2d19bd..f6180ac 100644 --- a/KamihamaWeb/Views/Home/Index.cshtml +++ b/KamihamaWeb/Views/Home/Index.cshtml @@ -3,6 +3,6 @@ }
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Kamihama API

+

This isn't the page you're looking for.

diff --git a/KamihamaWeb/Views/Home/Privacy.cshtml b/KamihamaWeb/Views/Home/Privacy.cshtml index af4fb19..5858827 100644 --- a/KamihamaWeb/Views/Home/Privacy.cshtml +++ b/KamihamaWeb/Views/Home/Privacy.cshtml @@ -3,4 +3,4 @@ }

@ViewData["Title"]

-

Use this page to detail your site's privacy policy.

+

diff --git a/KamihamaWeb/Views/Shared/HttpError.cshtml b/KamihamaWeb/Views/Shared/HttpError.cshtml new file mode 100644 index 0000000..0448793 --- /dev/null +++ b/KamihamaWeb/Views/Shared/HttpError.cshtml @@ -0,0 +1,4 @@ +
+

Kamihama API Error

+

@ViewData["ErrorMessage"]

+
diff --git a/KamihamaWeb/Views/Shared/_Layout.cshtml b/KamihamaWeb/Views/Shared/_Layout.cshtml index c38ea15..2043d66 100644 --- a/KamihamaWeb/Views/Shared/_Layout.cshtml +++ b/KamihamaWeb/Views/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewData["Title"] - KamihamaWeb + @ViewData["Title"] - Kamihama @@ -11,7 +11,7 @@