Rev | Line | |
---|
[d23bf72] | 1 | using System.Net;
|
---|
| 2 | using Microsoft.AspNetCore.Diagnostics;
|
---|
[6f203af] | 3 | using Microsoft.AspNetCore.Mvc;
|
---|
[d23bf72] | 4 | using Microsoft.Extensions.Logging;
|
---|
[6f203af] | 5 |
|
---|
| 6 | namespace Farmatiko.Controllers
|
---|
| 7 | {
|
---|
[d23bf72] | 8 | [ApiController]
|
---|
[6f203af] | 9 | public class ErrorController : Controller
|
---|
| 10 | {
|
---|
[d23bf72] | 11 | private readonly ILogger<ErrorController> _logger;
|
---|
| 12 |
|
---|
| 13 | public ErrorController(ILogger<ErrorController> logger)
|
---|
| 14 | {
|
---|
| 15 | _logger = logger;
|
---|
| 16 | }
|
---|
| 17 | [Route("/Error")]
|
---|
| 18 | public IActionResult Error()
|
---|
[6f203af] | 19 | {
|
---|
[d23bf72] | 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);
|
---|
[6f203af] | 30 | }
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.