Error Codes
Understanding and handling API errors in your VasBox integration.
When an API request fails, VasBox returns a structured error response with details to help you understand and resolve the issue.
Error Format
All error responses follow a consistent JSON format:
Error Response
{
"error": {
"code": "validation_error",
"message": "The given data was invalid.",
"details": {
"customer_id": ["The customer_id field is required."],
"items": ["The items field must have at least 1 item."]
},
"request_id": "req_abc123xyz"
}
}
Error Fields
| Field | Type | Description |
|---|---|---|
| code | string | Machine-readable error code |
| message | string | Human-readable error message |
| details | object | Additional error details (optional) |
| request_id | string | Unique request ID for support |
ZIMRA-Specific Errors
When submitting to ZIMRA, you may receive additional error details:
JSON
{
"error": {
"code": "zimra_submission_failed",
"message": "ZIMRA rejected the invoice submission.",
"details": {
"zimra_code": "ERR_INVALID_TIN",
"zimra_message": "Customer TIN is not registered with ZIMRA"
},
"request_id": "req_def456uvw"
}
}
Error Codes
The following error codes may be returned by the API:
General Errors
| Code | HTTP | Description |
|---|---|---|
| authentication_required | 401 | No API key provided |
| invalid_api_key | 401 | The API key is invalid or expired |
| permission_denied | 403 | API key lacks required permissions |
| resource_not_found | 404 | The requested resource does not exist |
| validation_error | 422 | Request validation failed |
| rate_limit_exceeded | 429 | Too many requests |
| internal_error | 500 | Internal server error |
Invoice Errors
| Code | HTTP | Description |
|---|---|---|
| invoice_not_found | 404 | Invoice does not exist |
| invoice_already_submitted | 422 | Invoice already submitted to ZIMRA |
| invoice_not_submittable | 422 | Invoice is not in submittable state |
| invoice_void_failed | 422 | Cannot void this invoice |
ZIMRA Errors
| Code | HTTP | Description |
|---|---|---|
| zimra_submission_failed | 422 | ZIMRA rejected the submission |
| zimra_invalid_tin | 422 | Customer TIN is invalid or not registered |
| zimra_tax_mismatch | 422 | Tax calculation does not match ZIMRA rules |
| zimra_unavailable | 503 | ZIMRA service temporarily unavailable |
Handling Errors
Here's how to handle errors in your application using our SDKs:
PHP
PHP
<?php
use VasBox\VasBox;
use VasBox\Exceptions\ValidationException;
use VasBox\Exceptions\ZimraException;
use VasBox\Exceptions\RateLimitException;
$vasbox = new VasBox(env('VASBOX_API_KEY'));
try {
$invoice = $vasbox->invoices->create([
'customer_id' => 'cust_123',
'items' => [],
]);
} catch (ValidationException $e) {
// Handle validation errors
foreach ($e->getErrors() as $field => $messages) {
echo "$field: " . implode(', ', $messages);
}
} catch (ZimraException $e) {
// Handle ZIMRA-specific errors
echo "ZIMRA Error: " . $e->getZimraCode();
} catch (RateLimitException $e) {
// Handle rate limiting - retry after delay
sleep($e->getRetryAfter());
} catch (\Exception $e) {
// Handle other errors
echo "Error: " . $e->getMessage();
}
JavaScript
JavaScript
import { VasBox, ValidationError, ZimraError, RateLimitError } from '@vasbox/sdk';
const vasbox = new VasBox(process.env.VASBOX_API_KEY);
try {
const invoice = await vasbox.invoices.create({
customer_id: 'cust_123',
items: [],
});
} catch (error) {
if (error instanceof ValidationError) {
// Handle validation errors
Object.entries(error.details).forEach(([field, messages]) => {
console.log(`${field}: ${messages.join(', ')}`);
});
} else if (error instanceof ZimraError) {
// Handle ZIMRA-specific errors
console.log('ZIMRA Error:', error.zimraCode);
} else if (error instanceof RateLimitError) {
// Handle rate limiting - retry after delay
await new Promise(r => setTimeout(r, error.retryAfter * 1000));
} else {
// Handle other errors
console.error('Error:', error.message);
}
}
Request ID
Always log the
request_id from error responses. This helps our support team quickly locate and diagnose issues. Previous Endpoints
NextRate Limits