Skip to main content

Error Handling

Handle errors gracefully in your AccruPay integration.

Error Types

Authentication Errors

Occur when API credentials are invalid or expired.

sdk = new AccruPay({
// ...
onAuthError: () => {
console.error('Authentication failed');
// Re-authenticate or alert user
},
});

GraphQL Errors

Validation or business logic errors.

onGraphQLError: (errors) sn=> {
errors.forEach(error => {
console.error('Error:', error.message);
console.error('Code:', error.extensions?.code);
});
},

Network Errors

Connection timeouts or network issues.

onNetworkError: (error) => {
console.error('Network issue:', error.message);
// Implement retry logic
},

Retry Strategies

Implement exponential backoff for transient errors:

async function retryWithBackoff(fn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
}
}
}