source: Farmatiko/Controllers/ErrorController.cs@ d23bf72

Last change on this file since d23bf72 was d23bf72, checked in by DimitarSlezenkovski <dslezenkovski@…>, 2 years ago

Add SystemService, Auth, fix a lil bugs :)

  • Property mode set to 100644
File size: 1.1 KB
Line 
1using System.Net;
2using Microsoft.AspNetCore.Diagnostics;
3using Microsoft.AspNetCore.Mvc;
4using Microsoft.Extensions.Logging;
5
6namespace Farmatiko.Controllers
7{
8 [ApiController]
9 public class ErrorController : Controller
10 {
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()
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);
30 }
31 }
32}
Note: See TracBrowser for help on using the repository browser.