Errors

When using the Offerte Adviseur API, you may encounter various types of errors. This guide explains the different status codes and error types you might receive, and how to handle them appropriately.

You can determine if your request was successful by checking the HTTP status code of the response. For unsuccessful requests, the response will include an error message and additional details to help you understand and resolve the issue.


Status codes

Here are the HTTP status codes you may encounter when using the Offerte Adviseur API:

  • Name
    200 OK
    Description
    The request was successful.
  • Name
    201 Created
    Description
    The resource was successfully created.
  • Name
    400 Bad Request
    Description

    The request was invalid or missing required parameters.

  • Name
    401 Unauthorized
    Description

    Authentication is required or the provided credentials are invalid.

  • Name
    403 Forbidden
    Description

    The authenticated user doesn't have permission to access the resource.

  • Name
    404 Not Found
    Description

    The requested resource doesn't exist.

  • Name
    422 Unprocessable Entity
    Description

    The request was well-formed but contains invalid parameters.

  • Name
    429 Too Many Requests
    Description

    You've exceeded the rate limit for API requests.

  • Name
    500 Internal Server Error
    Description

    Something went wrong on our servers. If this persists, please contact support.


Error handling examples

When a request fails, the API returns an error response containing details about what went wrong. Here are examples of handling different error scenarios in each supported language.

# Example handling a validation error response
response=$(curl -s -w "\n%{http_code}" \
  https://app.offerteadviseur.nl/api/leads \
  -H "Authorization: Bearer eyJ..." \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{}')

http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')

if [ "$http_code" -eq 422 ]; then
  echo "Validation error:"
  echo "$body" | jq -r '.errors | to_entries[] | "\(.key): \(.value[])"'
elif [ "$http_code" -eq 401 ]; then
  echo "Authentication error:"
  echo "$body" | jq -r '.message'
else
  echo "API error ($http_code):"
  echo "$body" | jq -r '.message'
fi

Common error responses

Here are examples of the error responses you might receive:

{
  "message": "The given data was invalid.",
  "errors": {
    "email": [
      "The email field is required."
    ],
    "phone": [
      "The phone number format is invalid."
    ]
  }
}

Error handling best practices

  1. Always check the HTTP status code of the response
  2. Parse the error message and validation errors when present
  3. Implement appropriate retry logic for rate limiting (429) errors
  4. Log detailed error information for debugging
  5. Display user-friendly error messages in your application

For detailed examples of error responses for specific endpoints, refer to their respective documentation sections.

Was this page helpful?