Skip to main content
The SDK provides a hierarchy of error classes for different failure scenarios.

Error Hierarchy

ComplianceError (base)
├── ValidationError
├── APIError
│   ├── NotFoundError
│   ├── UnauthorizedError
│   ├── ForbiddenError
│   ├── RateLimitError
│   ├── ServerError
│   ├── NetworkError
│   └── TimeoutError
└── UploadError
    ├── FileTooLargeError
    ├── UploadTimeoutError
    ├── InvalidFileTypeError
    ├── UploadAbortedError
    └── UploadUrlExpiredError

ComplianceError

Base class for all SDK errors.
import { ComplianceError } from "@artu-ai/compliance-sdk";

Properties

PropertyTypeDescription
messagestringHuman-readable error message
codestringError code
causeError | undefinedOriginal error if wrapped

Methods

MethodReturn TypeDescription
toJSON()objectSerializable representation

ValidationError

Thrown when input fails schema validation.
import { ValidationError } from "@artu-ai/compliance-sdk";

Properties

PropertyTypeDescription
issuesValidationIssue[]Array of validation issues

ValidationIssue

interface ValidationIssue {
  path: (string | number)[];
  message: string;
  code: string;
}

Example

try {
  await sdk.clients.create({ type: "invalid" });
} catch (error) {
  if (error instanceof ValidationError) {
    for (const issue of error.issues) {
      console.log(`${issue.path.join(".")}: ${issue.message}`);
    }
  }
}

APIError

Base class for API-related errors.
import { APIError, isAPIError } from "@artu-ai/compliance-sdk";

Properties

PropertyTypeDescription
statusCodenumberHTTP status code
requestIdstring | undefinedRequest ID for debugging

Type Guard

if (isAPIError(error)) {
  console.log(error.statusCode);
}

NotFoundError

Thrown when a resource is not found (404).
import { NotFoundError } from "@artu-ai/compliance-sdk";

Properties

PropertyTypeDescription
resourceIdstring | undefinedID of the missing resource
resourceTypestring | undefinedType of the missing resource

Example

try {
  await sdk.clients.retrieve("nonexistent_id");
} catch (error) {
  if (error instanceof NotFoundError) {
    console.log(`Resource not found: ${error.resourceId}`);
  }
}

UnauthorizedError

Thrown when authentication fails (401).
import { UnauthorizedError } from "@artu-ai/compliance-sdk";

Example

try {
  await sdk.clients.list();
} catch (error) {
  if (error instanceof UnauthorizedError) {
    console.log("Invalid API key");
  }
}

ForbiddenError

Thrown when access is denied (403).
import { ForbiddenError } from "@artu-ai/compliance-sdk";

Example

try {
  await sdk.alerts.generateReport("alert_id", "mex.actividad-vulnerable.avi");
} catch (error) {
  if (error instanceof ForbiddenError) {
    console.log("Insufficient permissions");
  }
}

RateLimitError

Thrown when rate limit is exceeded (429).
import { RateLimitError } from "@artu-ai/compliance-sdk";

Properties

PropertyTypeDescription
retryAfternumberSeconds to wait before retry

Example

try {
  await sdk.clients.list();
} catch (error) {
  if (error instanceof RateLimitError) {
    console.log(`Retry after ${error.retryAfter} seconds`);
    await sleep(error.retryAfter * 1000);
  }
}

ServerError

Thrown for server errors (5xx).
import { ServerError } from "@artu-ai/compliance-sdk";

Example

try {
  await sdk.clients.list();
} catch (error) {
  if (error instanceof ServerError) {
    console.log(`Server error: ${error.requestId}`);
  }
}

NetworkError

Thrown for network failures.
import { NetworkError } from "@artu-ai/compliance-sdk";

Example

try {
  await sdk.clients.list();
} catch (error) {
  if (error instanceof NetworkError) {
    console.log("Network error - check connection");
  }
}

TimeoutError

Thrown when request times out.
import { TimeoutError } from "@artu-ai/compliance-sdk";

Example

try {
  await sdk.clients.list();
} catch (error) {
  if (error instanceof TimeoutError) {
    console.log("Request timed out");
  }
}

UploadError

Base class for upload-related errors.
import { UploadError, isUploadError } from "@artu-ai/compliance-sdk";

Properties

PropertyTypeDescription
stageUploadStageStage where upload failed

UploadStage

type UploadStage = "request" | "upload" | "confirm";
ValueDescription
"request"Failed to request the presigned upload URL
"upload"Failed to upload the file bytes to storage
"confirm"Failed to confirm the upload with the API

Type Guard

if (isUploadError(error)) {
  console.log(`Upload failed at: ${error.stage}`);
}

FileTooLargeError

Thrown when file exceeds size limit.
import { FileTooLargeError } from "@artu-ai/compliance-sdk";

Properties

PropertyTypeDescription
maxSizenumberMaximum allowed size in bytes
actualSizenumberActual file size in bytes

InvalidFileTypeError

Thrown for unsupported file types.
import { InvalidFileTypeError } from "@artu-ai/compliance-sdk";

Properties

PropertyTypeDescription
mimeTypestringActual MIME type
allowedTypesstring[]Allowed MIME types

UploadTimeoutError

Thrown when upload times out.
import { UploadTimeoutError } from "@artu-ai/compliance-sdk";

UploadAbortedError

Thrown when upload is aborted.
import { UploadAbortedError } from "@artu-ai/compliance-sdk";

UploadUrlExpiredError

Thrown when upload URL has expired.
import { UploadUrlExpiredError } from "@artu-ai/compliance-sdk";