logoSemaphor

Error Handling

Understanding and handling API errors

Overview

The Semaphor API uses standard HTTP status codes and provides detailed error information to help you understand and resolve issues. All error responses follow a consistent format and are common across the Dashboards, Visuals, and Tokens APIs.

Error Response Format

All API errors return a JSON response with the following structure:

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error description",
    "details": {
      "field": "Additional error context",
      "suggestion": "Suggested solution"
    }
  }
}

HTTP Status Codes

Status CodeDescriptionCommon Causes
200SuccessRequest completed successfully
201CreatedResource created successfully
400Bad RequestInvalid request parameters or body
401UnauthorizedMissing or invalid authentication
403ForbiddenInsufficient permissions
404Not FoundResource doesn't exist
409ConflictResource conflict (e.g., duplicate)
422Unprocessable EntityValidation errors
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer-side error

Common Error Codes

Authentication & Token Errors (All APIs)

Error CodeStatusDescriptionSolution
INVALID_CREDENTIALS401Dashboard/project ID or secret is incorrectVerify credentials in Semaphor Console
TOKEN_EXPIRED401Authentication token has expiredGenerate a new token
INVALID_TOKEN401Token format is invalidCheck token format and regenerate
MISSING_AUTHORIZATION401Authorization header is missingInclude Authorization: Bearer {token} header
INSUFFICIENT_PERMISSIONS403Token lacks required permissionsCheck token configuration
RATE_LIMIT_EXCEEDED429Too many authentication attemptsWait before retrying

Dashboards API Errors

Error CodeStatusDescriptionSolution
DASHBOARD_NOT_FOUND404Dashboard doesn't existVerify dashboard ID
DASHBOARD_INACTIVE403Dashboard is not activeActivate dashboard in console
DASHBOARD_ARCHIVED403Dashboard has been archivedRestore dashboard or use different one
INVALID_DASHBOARD_ID400Dashboard ID format is invalidCheck ID format: d_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
EXPORT_FAILED500Export processing failedCheck export parameters and retry
INVALID_EXPORT_FORMAT400Unsupported export formatUse supported formats: png, jpg, pdf
EXPORT_TOO_LARGE400Export exceeds size limitsReduce dimensions or filters
EXPORT_NOT_FOUND404Export doesn't existVerify export ID
EXPORT_EXPIRED410Export has expiredGenerate new export

Visuals API Errors

Error CodeStatusDescriptionSolution
VISUAL_NOT_FOUND404Visual doesn't existVerify visual ID
INVALID_VISUAL_ID400Visual ID format is invalidCheck ID format
VISUAL_DUPLICATE409Visual already existsUse a unique title or ID

Security Policy Errors (Dashboards & Visuals)

Error CodeStatusDescriptionSolution
INVALID_SECURITY_POLICY400Security policy configuration is invalidReview policy syntax
POLICY_NOT_FOUND404Referenced policy doesn't existVerify policy name
POLICY_PARAMETER_MISMATCH400Policy parameters don't match expected formatCheck parameter types and values
POLICY_CONFLICT409Conflicting security policiesResolve policy conflicts

Validation Errors (All APIs)

Error CodeStatusDescriptionSolution
INVALID_PARAMETER400Request parameter is invalidCheck parameter format and values
MISSING_REQUIRED_FIELD400Required field is missingInclude all required fields
INVALID_JSON400Request body is not valid JSONCheck JSON syntax
FIELD_TOO_LONG400Field value exceeds maximum lengthReduce field length
INVALID_EMAIL_FORMAT400Email format is invalidUse valid email format

Error Handling Examples

See the Tokens API, Dashboards API, and Visuals API for endpoint-specific error examples and how to handle them in your code.

JavaScript/TypeScript

async function handleApiRequest(url: string, options: RequestInit) {
  try {
    const response = await fetch(url, options);
    if (!response.ok) {
      const errorData = await response.json();
      // ...handle errors as shown in the docs
    }
    return await response.json();
  } catch (error) {
    console.error('API request failed:', error);
    throw error;
  }
}

Best Practices

  • Always check the error.code and error.message fields in error responses.
  • Implement retry logic for rate limiting and server errors.
  • Log errors and monitor for recurring issues.
  • Validate all request parameters and payloads before sending.
  • Reference the Tokens API, Dashboards API, and Visuals API for more details on error handling in context.

On this page