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

FieldTypeDescription
codestringMachine-readable error code
messagestringHuman-readable error message
detailsobjectAdditional error details (optional)
request_idstringUnique 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

CodeHTTPDescription
authentication_required401No API key provided
invalid_api_key401The API key is invalid or expired
permission_denied403API key lacks required permissions
resource_not_found404The requested resource does not exist
validation_error422Request validation failed
rate_limit_exceeded429Too many requests
internal_error500Internal server error

Invoice Errors

CodeHTTPDescription
invoice_not_found404Invoice does not exist
invoice_already_submitted422Invoice already submitted to ZIMRA
invoice_not_submittable422Invoice is not in submittable state
invoice_void_failed422Cannot void this invoice

ZIMRA Errors

CodeHTTPDescription
zimra_submission_failed422ZIMRA rejected the submission
zimra_invalid_tin422Customer TIN is invalid or not registered
zimra_tax_mismatch422Tax calculation does not match ZIMRA rules
zimra_unavailable503ZIMRA 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.