3

I am working with a laravel project and willing to implement the best practice of web development. For some ajax requests, I am returning json response. For example, when I delete a record, I return 204 http status code

return response()->json([], 204);

But when I delete a record, I want to make sure the delete operation was successful. If the operation is not successful, I want to return a different status code and I want to know which status code is most appropriate for this case?

My code example is

if($department->delete()){

    //delete success and return 204
    return response()->json([], 204);

}else{
    //delete is not success, what is appropriate status code for this?
    return response()->json([], 500);
}
Ariful Haque
  • 3,662
  • 5
  • 37
  • 59
  • 4
    In my personal opinion, 500 is just fine there. – N.B. May 04 '15 at 18:00
  • 1
    500 is "Internal Server Error". When the server is unable to delete something on the database, that sounds like an internal server error, does it not? – sjagr May 04 '15 at 18:10
  • @sjagr thats what I wanted to be sure.. to know the industry best practice. – Ariful Haque May 04 '15 at 18:19
  • In general I don't think the user should care what _exactly_ went wrong. The website should just say there was a problem and try again/later/whatever. – Crembo May 04 '15 at 18:40

0 Answers0