Skip to content

roblohmann/CodeCube.StatusCodes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeCube.StatusCodes

Small library which allows you to use objectresults for the InternalServerError and BadGateway statuscodes.

Nuget Nuget (with prereleases) GitHub

Example .NET Core 3.x

Implementation in an base API-controller

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();
    }    
}

Example Usage in API Controller

public class MyAPIController : BaseAPIController
{
    public async Task<IActionResult> MyAction()
    {
        return InternalServerError("Some errormessage");
    }

    public async Task<IActionResult> MySecondAction()
    {
        return BadGateway("Some errormessage");
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages