1

我正在上传 dropbox.js。我正在检查服务器上的错误并通过 json 将它们返回到我的前端。到目前为止,一切都很好。

 header('HTTP/1.1 500 Internal Server Error');
            header('Content-Type: application/json; charset=UTF-8');
            die(json_encode(array('message' => 'ERROR', 'code' => 100)));

在我的前端,我可以捕捉到错误并做一些好事来提醒用户

error: function(file, errorMessage,  xhr) {
     console.log(xhr);
     // catch the error and alert the user
  }

问题是错误并不是真正的“服务器错误”,那么我应该如何在标题中返回它们?500 似乎不合适。我认为这并不重要,但很高兴返回正确类型的错误。

错误类型包括

  • 文件名不是唯一的
  • 错误的文件类型
  • 文件太大

什么是最好的状态码?

谢谢。

4

0 回答 0