Error Handling
AS2aaS provides detailed error information to help you diagnose and resolve issues quickly.
Error Response Format
{
"message": "Human-readable error description",
"errors": {
"field_name": ["Specific validation error"]
},
"error": {
"type": "error_category",
"code": "SPECIFIC_ERROR_CODE",
"details": {}
}
}
HTTP Status Codes
Status | Meaning | When It Occurs |
---|---|---|
400 | Bad Request | Invalid request format |
401 | Unauthorized | Invalid API key |
403 | Forbidden | Insufficient permissions |
404 | Not Found | Resource doesn't exist |
422 | Validation Error | Request data failed validation |
429 | Rate Limited | Too many requests |
500 | Internal Error | Server-side error |
Common Errors
Authentication Errors
Invalid API Key:
{
"error": {
"type": "authentication_error",
"code": "INVALID_API_KEY"
}
}
Partner Errors
Partner Not Found:
{
"error": {
"type": "resource_error",
"code": "PARTNER_NOT_FOUND",
"details": {
"partner_id": "prt_invalid"
}
}
}
Message Errors
Message Too Large:
{
"error": {
"type": "validation_error",
"code": "PAYLOAD_TOO_LARGE",
"details": {
"size_bytes": 104857600,
"max_size_bytes": 52428800
}
}
}
Certificate Errors
Certificate Expired:
{
"error": {
"type": "certificate_error",
"code": "CERTIFICATE_EXPIRED",
"details": {
"certificate_id": "cert_000001",
"expired_at": "2024-01-10T00:00:00Z"
}
}
}
Error Handling Patterns
Basic Error Handling
try {
const message = await as2.messages.create(messageData);
} catch (error) {
switch (error.code) {
case 'PARTNER_NOT_FOUND':
console.log('Partner not found - create partner first');
break;
case 'RATE_LIMITED':
await delay(error.details.retry_after * 1000);
break;
default:
console.error('Unexpected error:', error.message);
}
}
Retry Logic
async function sendWithRetry(data, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await as2.messages.create(data);
} catch (error) {
if (error.status === 422) throw error; // Don't retry validation errors
if (attempt === maxRetries) throw error;
const delay = Math.pow(2, attempt) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
}
}
}
Getting Help
For errors you can't resolve:
- Check error code in this documentation
- Use testing tools to reproduce safely
- Contact support with error details
- Check system status at status.as2aas.com