What http status code to return for "invalid state change"

Viewed 5396

This is a question about best REST practices. Considering the controller below which has a method which is supposed to update an application object.

public ApplicationController : Controller
{
    private readonly ApplicationService _applicationService;
    public ApplicationController(ApplicationService applicationService)
    {
       _applicationService = applicationService;
    }

    [HttpPost]
    public IActionResult Post([FromBodey] Application application)
    {
         var previousApplication = _applicationService.Get(applicationId)
         if(application.State == ApplicationState.Approved
             && apreviousApplcation.State != ApplicationState.Pending)
         {
              return StatusCode(*what code here*, "State have to be pending to goto approved");
         }

         _applicationSerivce.Update(application);
        return Ok();
    }
}

What status code would be best to return if it is not possible to change the state of the application to the new state?

1 Answers
Related