Question

What status code should be returned for a request to delete an object that doesn't exist?

public ContentResult DeleteEntity(int id, FormCollection FormData)
{
    Database db = new Database();
    TargetEntity te = db.TargetEntities.SingleOrDefault(t => t.Id == id);
    if(te == null)
    {
        Reponse.StatusCode = 400; //Is this correct?
        return Content("Deletion failed. Invalid ID: " + id);
    }
    //Delete the entity
    return Content("Successfully Deleted");
}

The request itself is fine, it just happens that the specified ID is invalid (or the item is already deleted), so I'm unsure about the 400 range. I'm pretty sure the 500 codes are even less-suited to this, since nothing went wrong on the server (it was just asked to delete something that doesn't exist).

What status code is most appropriate here?

Was it helpful?

Solution

What status code should be returned for a request to delete an object that doesn't exist?

404 - Not Found

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top