ErrorsController
parent
7ec5176555
commit
be4ce6cc83
|
@ -0,0 +1,28 @@
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Diagnostics;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace ProxmoxConnector.Server.Controllers
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ApiExplorerSettings(IgnoreApi = true)]
|
||||||
|
public class ErrorsController : ControllerBase
|
||||||
|
{
|
||||||
|
[Route("error")]
|
||||||
|
public IActionResult HandleErrors()
|
||||||
|
{
|
||||||
|
var context = HttpContext.Features.Get<IExceptionHandlerFeature>();
|
||||||
|
var exception = context.Error;
|
||||||
|
|
||||||
|
return exception switch
|
||||||
|
{
|
||||||
|
ValidationException => StatusCode(StatusCodes.Status404NotFound, new { exception.Message }),
|
||||||
|
UnauthorizedAccessException => StatusCode(StatusCodes.Status401Unauthorized, new { exception.Message }),
|
||||||
|
_ => StatusCode(StatusCodes.Status500InternalServerError),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue