Skip to main content

Error handling

Overview

Properly handling errors from the Atelio API is essential for building robust applications. This guide explains how to implement error handling for different types of API errors and provides code examples in common programming languages.

Atelio Error Responses

When an API request fails, Atelio returns a standardized error response with the following structure:

JSON
{
"Message": "Detailed error description",
"Status": 400,
"Code": "error_code",
"Type": "Request Error"
}

Each error response contains four key components:

ComponentDescription
CodeA specific error code that identifies the category of the error.
MessageA human-readable description of what went wrong.
StatusThe HTTP status code of the response.
TypeThe high-level category of the error: Request Error, Server Error, or Process Error.

For a comprehensive list of error codes and their meanings, see the Error Codes Dictionary.

Error Handling Strategies

4xx Request errors

Request errors indicate issues with the client's request that can typically be resolved by the end user.

Common causes:

  • Missing or invalid parameters
  • Invalid authentication
  • Resource not found
  • Schema validation failures

Handling strategy:

  • Parse the error message to identify the specific issue
  • Present clear feedback to the user about what went wrong
  • Allow the user to correct the issue and retry

5xx Server errors

Server errors indicate issues with Atelio's internal servers.

Handling strategy:

  • Implement retry logic with exponential backoff for transient issues
  • Log the complete error details for troubleshooting
  • Contact Atelio support if the issue persists
  • Display a user-friendly message that doesn't expose internal details

Process Errors

Process errors relate to the execution of a process at the backend.

Handling strategy:

  • Log the complete error details
  • Contact Atelio support
  • Implement appropriate fallback behavior in your application

Implementing Error Handling

async function makeAtelioApiRequest(endpoint, data) {
try {
const response = await fetch(`https://api.atelio.com/api/v0.1/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer <YOUR_AUTH_TOKEN>',
'Identity': '<YOUR_IDENTITY_KEY>'
},
body: JSON.stringify(data)
});

const responseData = await response.json();

// Check if the response contains an error
if (!response.ok) {
// Handle different error types
switch (responseData.Type) {
case 'Request Error':
console.error(`Request Error: ${responseData.Message} (${responseData.Code})`);
// Handle specific error codes
if (responseData.Code === 'create_transfer_schema') {
return { success: false, error: 'Please check the transfer details and try again.' };
}
break;

case 'Server Error':
console.error(`Server Error: ${responseData.Message} (${responseData.Code})`);
return { success: false, error: 'We\'re experiencing technical difficulties. Please try again later.' };

case 'Process Error':
console.error(`Process Error: ${responseData.Message} (${responseData.Code})`);
return { success: false, error: 'Your request could not be processed. Our team has been notified.' };

default:
console.error(`Unknown Error: ${responseData.Message}`);
return { success: false, error: 'An unexpected error occurred.' };
}

return { success: false, error: responseData.Message };
}

return { success: true, data: responseData };
} catch (error) {
console.error('Network or parsing error:', error);
return { success: false, error: 'Could not connect to the server. Please check your internet connection.' };
}
}

Best Practices for Error Handling

Best practiceDescription
Log comprehensive error detailsInclude the complete error response for debugging purposes.
Implement retry logic for transient errorsUse exponential backoff for server errors (5xx) that might be temporary.
Provide user-friendly error messagesTranslate technical error codes into actionable messages for end users.
Handle specific error codesImplement custom handling for common error codes relevant to your application.
Include error contextWhen logging errors, include the request context (endpoint, parameters) to aid troubleshooting.
Validate input before sendingPrevent common request errors by validating input on the client side.
Implement idempotencyFor critical operations, use idempotency keys to safely retry operations without side effects.

Idempotency in Error Handling

When implementing retry logic, it's important to use idempotency keys for operations that should not be duplicated, such as transfers or payments. Atelio supports idempotency for POST requests through the Idempotency-Key header:

JavaScript
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <YOUR_AUTH_TOKEN>',
'Identity': '<YOUR_IDENTITY_KEY>',
'Idempotency-Key': generateUniqueKey() // Generate a unique key for this specific operation
};

Idempotency keys ensure that even if you retry a request multiple times due to connection issues or server errors, the operation will only be executed once.