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?

有帮助吗?

解决方案

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

404 - Not Found

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top