The front-end requests the back-end interface to return an error code.

1. If the HTTP Code is within the 2xx range, it usually indicates that the request has been successfully processed, and the processing result of the request can be further determined based on the specific HTTP Code . for example:

  • HTTP Code 200 indicates that the request was successful and the requested resource was returned;
  • HTTP Code 204 indicates that the request was successful but no resources were returned;
  • HTTP Code 201 indicates that the request was successful and the newly created resource was returned;
  • HTTP Code 202 indicates that the request has been received but has not been processed yet.

2. If the return code ( HTTP Code ) is not in the 2xx range, it usually means that the request was not processed successfully and there may be some problems. Specifically:

  • HTTP Code 4xx usually indicates that the request sent by the client is incorrect, such as the requested URI is incorrect, the parameter format in the request is incorrect, etc. In this case, you need to check whether the parameters, URI , request method, etc. of the current request are legal and whether they are missing necessary parameters, etc.
  • HTTP Code 5xx usually indicates that the server has an error when processing the request, such as the server is busy, the back-end service is abnormal, etc. In this case, you need to confirm whether the request address, parameters, etc. are correct, and you can also try to retry the current request.

2.1 HTTP Code 4xx (Client Error) means that the request contained an error or could not be completed, which is usually caused by the client sending a bad request. The following are various situations of HTTP Code 4xx :

  • 400 Bad Request : The request format is incorrect, such as the request parameters are missing or incorrectly formatted.
  • 401 Unauthorized : Authentication is required, but the client did not provide valid identity credentials.
  • 403 Forbidden: Access to the requested resource is denied.
  • 404 Not Found : The requested resource does not exist.
  • 405 Method Not Allowed (This method is not allowed): The request method is not allowed, such as PUT , etc.
  • 410 Gone (no longer exists): The requested resource has been permanently deleted.
  • 429 Too Many Requests : Due to frequent repeated requests, the server refuses to provide services and requires the client to try again later.

2.2 HTTP Code 5xx (server error) means that the request has been accepted, but the server encountered an error when processing the request, which is equivalent to an exception on the server side. The following are various situations of HTTP Code 5xx :

  • 500 Internal Server Error : An error occurred when the server processed the request. The client should not be responsible for this error. You need to contact the relevant personnel maintaining the server.
  • 502 Bad Gateway : The server acting as a proxy or gateway received a bad response from the server.
  • 503 Service Unavailable : The server is currently unable to process the request, possibly due to system maintenance or too many requests in progress.
  • 504 Gateway Timeout : The server, acting as a proxy or gateway, cannot receive the request response within the specified time.

In actual use, when encountering HTTP Code 4xx and HTTP Code 5xx , you need to analyze and troubleshoot based on the specific error causes. You may need to check whether the request parameters, request method, request address, etc. are correct, or you may need to contact the relevant personnel maintaining the server for help.

Guess you like

Origin blog.csdn.net/wuxiaoquan_520/article/details/131993807