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

StatusMeaningWhen It Occurs
400Bad RequestInvalid request format
401UnauthorizedInvalid API key
403ForbiddenInsufficient permissions
404Not FoundResource doesn't exist
422Validation ErrorRequest data failed validation
429Rate LimitedToo many requests
500Internal ErrorServer-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:

  1. Check error code in this documentation
  2. Use testing tools to reproduce safely
  3. Contact support with error details
  4. Check system status at status.as2aas.com