Skip to main content

Error Handling

Error handling is a critical aspect of API integration, ensuring your application can gracefully respond to unexpected situations. HTTP status codes provide standardized ways to communicate error types, while structured error responses give detailed information about what went wrong. Proper error handling prevents application crashes and provides better user experiences.

Error Structure

covosign returns errors in a consistent JSON format that includes a success flag, error details, and optional additional information. The 'error' object contains a machine-readable code, a human-readable message, and sometimes field-specific details. HTTP status codes follow REST conventions: 4xx for client errors (your fault) and 5xx for server errors (our fault).

Client errors (4xx) cover validation, auth, and conflicts; server errors (5xx) are transient and should be retried with backoff.

{
"code": 400,
"statusText": "Bad Request",
"message": "Invalid email format"
}

Common Codes

The table below lists frequently encountered HTTP status codes and their corresponding error codes in covosign. Status codes in the 400s indicate client-side issues that you can fix, while 400s indicate server problems. Each error code provides specific information about the type of problem encountered, helping you diagnose and resolve issues quickly.

StatusCodeMeaning
400VALIDATION_ERRORInvalid request parameters
401INVALID_API_KEYAuthentication failed
429RATE_LIMIT_EXCEEDEDToo many requests

Retry Strategy

When API calls fail due to transient issues (like network problems or temporary server overload), implementing a retry strategy can improve reliability. Exponential backoff increases the wait time between retries to avoid overwhelming the server. The examples below show implementations that retry up to 3 times with increasing delays, but only for server errors (5xx status codes).

async function requestWithRetry(method, url, data, maxRetries = 3) {
let attempt = 0;
while (attempt < maxRetries) {
try {
const response = await axios({ method, url, data, headers: { 'X-API-Key': process.env.API_KEY } });
return response.data;
} catch (error) {
if (error.response && error.response.status < 500) throw error;
attempt++;
await new Promise(r => setTimeout(r, Math.pow(2, attempt) * 1000));
}
}
throw new Error('Max retries exceeded');
}