Skip to content

Error Codes

Complete reference for InvoisX API error codes.

Error Response Format

json
{
  "success": false,
  "message": "Human-readable error message",
  "error_code": "ERROR_CODE",
  "errors": {
    // Optional: field-specific errors
  }
}

HTTP Status Codes

StatusMeaning
200Success
201Created
204No Content (successful delete)
400Bad Request
401Unauthorized
403Forbidden
404Not Found
422Validation Error
429Too Many Requests
500Server Error

Authentication Errors

CodeHTTPDescription
UNAUTHORIZED401Missing or invalid token
TOKEN_EXPIRED401Token has expired
FORBIDDEN403Insufficient permissions
COMPANY_ACCESS_DENIED403Token not linked to company

Example

json
{
  "success": false,
  "message": "Unauthenticated.",
  "error_code": "UNAUTHORIZED"
}

Validation Errors

CodeHTTPDescription
VALIDATION_FAILED422Request validation failed

Example

json
{
  "success": false,
  "message": "The given data was invalid.",
  "error_code": "VALIDATION_FAILED",
  "errors": {
    "buyerId": ["The buyer id field is required."],
    "invoiceLines.0.unitPrice": ["The unit price must be a number."]
  }
}

Document Errors

CodeHTTPDescription
DOCUMENT_NOT_FOUND404Document doesn't exist
DOCUMENT_NOT_DRAFT403Operation requires draft status
DOCUMENT_NOT_READY422Document must be validated first
DOCUMENT_NOT_VALID422Operation requires valid status
DOCUMENT_READ_ONLY403Cannot modify submitted document

Example

json
{
  "success": false,
  "message": "Document must be validated and in 'ready' status before submission",
  "error_code": "DOCUMENT_NOT_READY"
}

LHDN Errors

CodeHTTPDescription
LHDN_REJECTED422LHDN rejected the document
LHDN_VALIDATION_FAILED422LHDN validation error
LHDN_CONNECTION_ERROR503Cannot connect to LHDN

Example

json
{
  "success": false,
  "message": "LHDN rejected the document",
  "error_code": "LHDN_REJECTED",
  "errors": {
    "lhdn_error": {
      "code": "ERR001",
      "message": "Invalid TIN format"
    }
  }
}

Quota Errors

CodeHTTPDescription
QUOTA_EXCEEDED429Submission quota exceeded
SUBSCRIPTION_REQUIRED403Active subscription required
SUBSCRIPTION_EXPIRED403Subscription has expired

Example

json
{
  "success": false,
  "message": "Document quota exceeded. You have 0 documents remaining out of 100.",
  "error_code": "QUOTA_EXCEEDED"
}

Resource Errors

CodeHTTPDescription
NOT_FOUND404Resource not found
BUYER_NOT_FOUND404Buyer doesn't exist
SELLER_NOT_FOUND404On-behalf seller doesn't exist
BUYER_HAS_INVOICES409Cannot delete buyer with invoices
SELLER_HAS_INVOICES409Cannot delete seller with invoices
BUYER_NOT_READY422Buyer missing required fields

Example

json
{
  "success": false,
  "message": "Cannot delete buyer: has existing invoices",
  "error_code": "BUYER_HAS_INVOICES"
}

Rate Limit Errors

CodeHTTPDescription
RATE_LIMIT_EXCEEDED429Too many requests

Example

json
{
  "success": false,
  "message": "Too many requests. Please try again in 60 seconds.",
  "error_code": "RATE_LIMIT_EXCEEDED"
}

Handling Errors

JavaScript

javascript
try {
  const response = await api('POST', '/invoices', data);
} catch (error) {
  const errorCode = error.response?.data?.error_code;

  switch (errorCode) {
    case 'VALIDATION_FAILED':
      // Handle validation errors
      const errors = error.response?.data?.errors;
      Object.entries(errors).forEach(([field, messages]) => {
        console.log(`${field}: ${messages.join(', ')}`);
      });
      break;

    case 'DOCUMENT_NOT_READY':
      // Validate first
      await api('POST', `/documents/${id}/validate`);
      break;

    case 'QUOTA_EXCEEDED':
      // Upgrade subscription
      console.log('Please upgrade your subscription');
      break;

    case 'LHDN_REJECTED':
      // Check LHDN error details
      const lhdnError = error.response?.data?.errors?.lhdn_error;
      console.log(`LHDN Error: ${lhdnError?.message}`);
      break;

    default:
      console.log(`Error: ${error.message}`);
  }
}

Python

python
try:
    response = api('POST', '/invoices', data)
except APIError as e:
    if e.error_code == 'VALIDATION_FAILED':
        for field, messages in e.errors.items():
            print(f"{field}: {', '.join(messages)}")

    elif e.error_code == 'DOCUMENT_NOT_READY':
        api('POST', f'/documents/{id}/validate')

    elif e.error_code == 'QUOTA_EXCEEDED':
        print('Please upgrade your subscription')

    elif e.error_code == 'LHDN_REJECTED':
        lhdn_error = e.errors.get('lhdn_error', {})
        print(f"LHDN Error: {lhdn_error.get('message')}")

    else:
        print(f"Error: {e.message}")

PHP

php
try {
    $response = $api->post('/invoices', $data);
} catch (RequestException $e) {
    $errorCode = $e->response->json('error_code');

    match ($errorCode) {
        'VALIDATION_FAILED' => handleValidationErrors($e->response->json('errors')),
        'DOCUMENT_NOT_READY' => $api->post("/documents/$id/validate"),
        'QUOTA_EXCEEDED' => throw new Exception('Please upgrade your subscription'),
        'LHDN_REJECTED' => handleLhdnError($e->response->json('errors.lhdn_error')),
        default => throw $e,
    };
}

InvoisX - Malaysia's Leading e-Invoice Platform