Error Handling

Learn how to properly handle errors returned by the Unduit API.

Error Handling is Critical

Always implement comprehensive error handling in your API integration.

HTTP Status Codes

400

Bad Request

Validation failed.

401

Unauthorized

Authentication failed.

404

Not Found

Resource not found.

429

Too Many Requests

Rate limit exceeded.

Error Response Format

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error message",
    "details": [
      {
        "field": "fieldName",
        "message": "Field-specific error"
      }
    ]
  }
}

Best Practices

Log errors with context

Include timestamps and request details.

Implement exponential backoff

Retry with increasing delays.

Never expose sensitive errors

Show user-friendly messages only.

Handling 401 Errors

if (response.status === 401) {
  const data = await response.json();
  if (data.error.code === 'TOKEN_EXPIRED') {
    // Try refreshing the token
    await refreshAccessToken();
  } else {
    // Redirect to login
    window.location.href = '/login';
  }
}

Next Steps