Skip to content

Error Handling

thelawin.dev uses standard HTTP status codes and detailed JSON error responses.

HTTP Status Codes

CodeMeaning
200Success
400Bad Request - Invalid input
401Unauthorized - Invalid API key
403Forbidden - Key doesn't have access
429Too Many Requests - Rate limited
500Server Error - Contact support

Error Response Format

All errors follow this structure:

json
{
  "error": "validation_failed",
  "message": "Invoice validation failed",
  "details": [
    {
      "path": "$.invoice.seller.vatId",
      "code": "REQUIRED",
      "message": "Seller VAT ID is required"
    }
  ]
}

Error Types

validation_failed

Input validation errors. Check the details array for specific issues.

json
{
  "error": "validation_failed",
  "details": [
    {
      "path": "$.invoice.number",
      "code": "REQUIRED",
      "message": "Invoice number is required"
    }
  ]
}

invalid_api_key

The provided API key is invalid or has been revoked.

json
{
  "error": "invalid_api_key",
  "message": "The provided API key is invalid"
}

quota_exceeded

Monthly quota has been reached.

json
{
  "error": "quota_exceeded",
  "message": "Monthly quota exceeded",
  "account": {
    "remaining": 0,
    "plan": "starter",
    "reset_at": "2026-02-01T00:00:00Z"
  }
}

rate_limited

Too many requests in a short time period.

json
{
  "error": "rate_limited",
  "message": "Rate limit exceeded",
  "retry_after": 60
}

JSON Path Format

Error paths use JSON Path notation to identify the exact field:

PathMeaning
$.invoice.numberInvoice number field
$.invoice.seller.nameSeller's name
$.invoice.items[0].quantityFirst item's quantity

Handling Errors in SDKs

TypeScript

typescript
const result = await client.invoice()
  .number('2026-001')
  .generate()

if (!result.success) {
  result.errors.forEach(error => {
    console.error(`${error.path}: ${error.message}`)
  })
}

Python

python
result = client.invoice().number("2026-001").generate()

if not result.success:
    for error in result.errors:
        print(f"{error.path}: {error.message}")

Best Practices

  1. Always check for errors - Don't assume requests succeed
  2. Log error details - Include the full error response for debugging
  3. Handle rate limits - Implement exponential backoff
  4. Validate before sending - Use client-side validation to catch errors early

ZUGFeRD 2.3 & Factur-X 1.0 compliant