Documentation Index
Fetch the complete documentation index at: https://docs.artosai.com/llms.txt
Use this file to discover all available pages before exploring further.
npm SDK Error Handling
The SDK throws ArtosAPIError for API-related errors. Always wrap SDK calls in try-catch blocks.
Basic Error Handling
import { getTemplateUrl, ArtosAPIError } from '@artosai/sdk'
async function safeGetTemplate(documentId) {
try {
const result = await getTemplateUrl({
documentId,
accessToken: process.env.ARTOS_ACCESS_TOKEN,
baseUrl: 'https://api.artosai.com'
})
return { success: true, data: result }
} catch (error) {
if (error instanceof ArtosAPIError) {
console.error(`API Error (${error.status}): ${error.message}`)
switch (error.status) {
case 401:
return { success: false, error: 'Invalid or expired access token' }
case 403:
return { success: false, error: 'Access denied to this document' }
case 404:
return { success: false, error: 'Document not found' }
default:
return { success: false, error: `API error: ${error.message}` }
}
}
console.error('Unexpected error:', error)
return { success: false, error: 'An unexpected error occurred' }
}
}
Common Error Codes
| Status Code | Description | Recommended Action |
|---|
| 400 | Bad Request | Check your request parameters |
| 401 | Unauthorized | Verify your access token is valid |
| 403 | Forbidden | Confirm you have access to this resource |
| 404 | Not Found | Verify the document ID exists |
| 500 | Server Error | Retry the request or contact support |
Retry Logic
For transient failures, implement retry logic with exponential backoff:
async function withRetry(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(r => setTimeout(r, 1000 * (i + 1)))
}
}
}
// Usage
const result = await withRetry(() => getTemplateUrl({
documentId: 'doc-123',
accessToken: token,
baseUrl: 'https://api.artosai.com'
}))
Support
For technical assistance or questions:
When contacting support, please include:
- Your organization ID
- The SDK version (
npm list @artosai/sdk)
- Error messages and stack traces
- Steps to reproduce the issue