Overview
The TerraQuake API uses standard HTTP status codes and returns consistent error response formats to help you identify and handle issues effectively. All errors include descriptive messages and metadata to assist with debugging.Error Response Format
All error responses follow this standardized structure:Error Response Fields
boolean
Always
false for error responsesinteger
HTTP status code (400, 404, 429, 500, 503, etc.)
string
Human-readable error description explaining what went wrong and how to fix it
object
Additional metadata about the error
HTTP Status Codes
The API uses standard HTTP status codes to indicate the success or failure of requests:Success Codes
success
Request succeeded. The response body contains the requested data.
Client Error Codes (4xx)
error
Invalid request parameters or malformed request.Common causes:
- Invalid pagination parameters (page < 1, limit < 1)
- Invalid date formats
- Missing required parameters
- Invalid parameter types
error
The requested resource does not exist.Common causes:
- Invalid endpoint URL
- Non-existent earthquake ID
- Unavailable region
error
Rate limit exceeded.Solution: Wait for the duration specified in the
Retry-After header before retrying.See Rate Limiting for more details.Server Error Codes (5xx)
error
An unexpected error occurred on the server.What to do:
- Retry the request after a brief delay
- If the error persists, contact support
The upstream data source (INGV API) is temporarily unavailable.What to do:
- Retry the request after a few seconds
- Implement exponential backoff for retries
Common Error Scenarios
Invalid Pagination Parameters
Request:Rate Limit Exceeded
Request:Upstream Service Error
Request:Invalid Date Format
Request:Not Found Error
Request:Error Handling Implementation
The API uses a centralized error handler utility for consistent error responses:/home/daytona/workspace/source/backend/src/utils/handleHttpError.js:5-19
Handling Errors in Your Code
JavaScript/TypeScript
Python
Go
Best Practices
1
Always Check Response Status
Don’t assume requests succeed. Always check the HTTP status code or the
success field in the response.2
Implement Retry Logic
For server errors (5xx) and rate limits (429), implement retry logic with exponential backoff.
3
Log Errors for Debugging
Always log error details including the timestamp, status code, and message for debugging.
4
Handle Rate Limits Gracefully
Use the
Retry-After header to determine when to retry after hitting rate limits.See Rate Limiting for detailed examples.5
Validate Input Before Sending
Validate parameters client-side before making requests to catch errors early.
6
Set Appropriate Timeouts
Set reasonable request timeouts to avoid hanging requests.
Error Monitoring
For production applications, implement error monitoring:Common Questions
What's the difference between 500 and 503 errors?
What's the difference between 500 and 503 errors?
- 500 (Internal Server Error): An unexpected error in the TerraQuake API itself
- 503 (Service Unavailable): The upstream INGV data source is temporarily unavailable
Should I retry on 4xx errors?
Should I retry on 4xx errors?
No. 4xx errors indicate client-side problems (invalid parameters, rate limits, etc.). Fix the request instead of retrying, except for 429 (rate limit) where you should wait and retry.
How long should I wait before retrying?
How long should I wait before retrying?
- 429 errors: Use the
Retry-Afterheader value - 5xx errors: Use exponential backoff (1s, 2s, 4s, etc.)
- Network errors: Start with 1s and increase exponentially
What if the error message is unclear?
What if the error message is unclear?
Error messages are designed to be descriptive. If you encounter an unclear error, check:
- The HTTP status code
- The timestamp in
meta.timestamp - Your request parameters