I am using the libraries Microsoft.AspNetCore.Http
and Microsoft.AspNetCore.Mvc
. I am also using Identity's JWT token.
When the token has expired, the API throws a http 401 error, and if the claims are wrong, it returns a http 403 error.
I need to be able to catch those two statues and wrap them in my uniform error message format
public class ErrorMessage
{
public int httpStatus { get; set; }
public string Header { get; set; } = "Error";
public string Message { get; set; }
}
My Standard API format
[Authorize]
[HttpPost]
[Route("Logout")]
public async Task<IActionResult> Logout()
{
try
{
....
}
catch (Exception e)
{
_logger.LogError($"Error in {nameof(Login)}: {e}");
return BadRequest(new ErrorMessage { httpStatus = 500, Message = e.Message });
}
}