Changeset d23bf72 for Farmatiko/Controllers/ErrorController.cs
- Timestamp:
- 11/05/20 06:57:35 (4 years ago)
- Branches:
- master
- Children:
- afc9a9a
- Parents:
- 1f4846d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/Controllers/ErrorController.cs
r1f4846d rd23bf72 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 1 using System.Net; 2 using Microsoft.AspNetCore.Diagnostics; 5 3 using Microsoft.AspNetCore.Mvc; 4 using Microsoft.Extensions.Logging; 6 5 7 6 namespace Farmatiko.Controllers 8 7 { 8 [ApiController] 9 9 public class ErrorController : Controller 10 10 { 11 public IActionResult Index() 11 private readonly ILogger<ErrorController> _logger; 12 13 public ErrorController(ILogger<ErrorController> logger) 12 14 { 13 return View(); 15 _logger = logger; 16 } 17 [Route("/Error")] 18 public IActionResult Error() 19 { 20 var exception = HttpContext.Features.Get<IExceptionHandlerFeature>(); 21 var statusCode = exception.Error.GetType().Name switch 22 { 23 "ArgumentException" => HttpStatusCode.BadRequest, 24 "Exception" => HttpStatusCode.InternalServerError, 25 /*"NotFoundResult" => HttpStatusCode.NotFound,*/ 26 _ => HttpStatusCode.ServiceUnavailable 27 }; 28 _logger.LogInformation(statusCode.ToString() + " " + exception.ToString()); 29 return Problem(detail: exception.Error.Message, statusCode: (int)statusCode); 14 30 } 15 31 }
Note:
See TracChangeset
for help on using the changeset viewer.