Ignore:
Timestamp:
11/05/20 06:57:35 (3 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
afc9a9a
Parents:
1f4846d
Message:

Add SystemService, Auth, fix a lil bugs :)

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;
     1using System.Net;
     2using Microsoft.AspNetCore.Diagnostics;
    53using Microsoft.AspNetCore.Mvc;
     4using Microsoft.Extensions.Logging;
    65
    76namespace Farmatiko.Controllers
    87{
     8    [ApiController]
    99    public class ErrorController : Controller
    1010    {
    11         public IActionResult Index()
     11        private readonly ILogger<ErrorController> _logger;
     12
     13        public ErrorController(ILogger<ErrorController> logger)
    1214        {
    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);
    1430        }
    1531    }
Note: See TracChangeset for help on using the changeset viewer.