Error Handling

All API errors return a consistent JSON structure with a machine-readable code and human-readable message.

Error format

{
  "error": {
    "code": "auth.unauthorized",
    "message": "Invalid or missing API key"
  }
}

Error codes

StatusCodeMeaning
401auth.unauthorizedMissing or invalid API key
403auth.forbiddenKey valid but insufficient permissions
404not_foundResource does not exist
409conflictDuplicate or conflicting resource
422validation.failedRequest body failed schema validation
429rate_limit.exceededToo many requests
500internalServer error

SDK error handling

import { HelmdeskError } from '@helmdesk/sdk'

try {
  await client.tickets.get('invalid-id')
} catch (err) {
  if (err instanceof HelmdeskError) {
    console.log(err.status) // 404
    console.log(err.code)   // "not_found"
    console.log(err.message) // "Ticket not found"
  }
}

Validation errors

When a 422 error occurs, the response includes a details object with field-level errors:

{
  "error": {
    "code": "validation.failed",
    "message": "Validation failed",
    "details": {
      "subject": "Required",
      "customerEmail": "Invalid email address"
    }
  }
}