DocumentFlow
Error Handling
When using the DocumentFlow API, you may encounter errors. This guide will help you understand and handle these errors effectively.
Error Response Format
When an error occurs, DocumentFlow will return a JSON response with details about the error. The response will include an error code, a message, and sometimes additional details.
{
"error": {
"code": "invalid_request",
"message": "The request was unacceptable, often due to missing a required parameter.",
"details": {
"missing_param": "document_url"
}
}
}
Common Error Codes
- invalid_request: The request was unacceptable, often due to missing a required parameter.
- authentication_error: No valid API key provided.
- rate_limit_exceeded: Too many requests hit the API too quickly.
- not_found: The requested resource doesn't exist.
- server_error: Something went wrong on DocumentFlow's end.
Handling Errors
When working with the DocumentFlow API, it's important to handle errors gracefully. Here's an example of how you might handle errors in JavaScript:
try {
const response = await documentFlow.processDocument({
url: 'https://example.com/document.pdf'
});
console.log(response);
} catch (error) {
if (error.response) {
console.error('Error:', error.response.data.error.message);
// Handle specific error codes
switch(error.response.data.error.code) {
case 'invalid_request':
// Handle invalid request
break;
case 'authentication_error':
// Handle authentication error
break;
// ... handle other error codes
}
} else {
console.error('Error:', error.message);
}
}
By properly handling errors, you can provide a better experience for your users and more easily debug issues when they occur.