문제

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