Error and Response Codes

Error and Response Codes

Understanding the response codes returned by the Gratero API is essential for effective error handling and debugging. Below is a list of the common HTTP status codes you may encounter when interacting with the Gratero API.

CodeStatusDescription
200OKThe request was successful, and the server returned the requested data.
201CreatedThe request was successful, and a new resource was created. This is typically returned after creating a new shipment.
400Bad RequestThe server could not understand the request due to invalid syntax. This may occur if the request body is malformed or missing required parameters.
401UnauthorizedAuthentication failed or the API key is missing. Ensure that you include a valid API key in the header.
403ForbiddenThe server understood the request but refuses to authorize it. This can happen if you do not have the necessary permissions to access the resource.
409ConflictThe request could not be processed because of a conflict with the current state of the resource. This typically occurs if the user has not verified their KYC details.
422Unprocessable EntityThe server understands the content type of the request entity, and the syntax of the request entity is correct, but balance in your wallet is insufficient to process this request.
429Too Many RequestsThe client has sent too many requests in a given amount of time. Slow down your request rate and try again later.
500Internal Server ErrorThe server encountered an internal error and was unable to complete your request. This is a generic error message and often indicates a problem with the server.

Handling Errors

When you receive an error response from the Gratero API, it is important to handle it gracefully in your application. Here are some general tips:

  • Check the Response Code: Use the response code to determine the type of error and take appropriate action.
  • Log the Error: Log the error details for debugging purposes.
  • Retry Mechanism: Implement a retry mechanism for transient errors like 500 Internal Server Error or 429 Too Many Requests.
  • User Feedback: Provide meaningful feedback to the user if an error occurs, so they understand what went wrong and how to correct it.