Small library which allows you to use objectresults for the InternalServerError and BadGateway statuscodes.
public abstract class BaseAPIController : ControllerBase
{
protected static InternalServerErrorObjectResult InternalServerError(string message)
{
return new InternalServerErrorObjectResult(message);
}
protected static InternalServerErrorObjectResult InternalServerError(ModelStateDictionary modelState)
{
return new InternalServerErrorObjectResult(modelState);
}
protected static InternalServerErrorResult InternalServerError()
{
return new InternalServerErrorResult();
}
protected static BadGatewayObjectResult BadGateway(string message)
{
return new BadGatewayObjectResult(message);
}
protected static BadGatewayObjectResult BadGateway(ModelStateDictionary modelState)
{
return new BadGatewayObjectResult(modelState);
}
protected static BadGatewayResult BadGateway()
{
return new BadGatewayResult();
}
}
public class MyAPIController : BaseAPIController
{
public async Task<IActionResult> MyAction()
{
return InternalServerError("Some errormessage");
}
public async Task<IActionResult> MySecondAction()
{
return BadGateway("Some errormessage");
}
}