Skip to main content

Overview

Factify uses conventional HTTP status codes and returns structured error responses.

Error Response Format

All errors follow a consistent JSON structure:
{
  "error": {
    "type": "invalid_request_error",
    "message": "Document title cannot be empty",
    "param": "title",
    "code": "missing_required_field"
  }
}
FieldTypeDescription
typestringError category for broad handling
codestringSpecific error for programmatic handling
messagestringHuman-readable explanation
paramstring | nullField that caused the error

Error Types

TypeHTTP StatusWhen
invalid_request_error400Validation failed, malformed request
authentication_error401Missing or invalid API key
authorization_error403Valid key, insufficient permissions
not_found_error404Resource doesn’t exist
rate_limit_error429Too many requests
api_error500+Server-side failure

SDK Error Classes

FactifyError is the base class for all HTTP error responses:
PropertyTypeDescription
error.messagestringError message
error.httpMeta.responseResponseHTTP response with headers
error.httpMeta.requestRequestHTTP request details
error.data$variesStructured error data

Handling Errors

import { Factify } from "@factify/sdk";
import * as errors from "@factify/sdk/models/errors";

const factify = new Factify({
  bearerAuth: process.env.FACTIFY_KEY,
});

async function run() {
  try {
    const result = await factify.documents.get({
      documentId: "doc_nonexistent",
    });
    console.log(result);
  } catch (error) {
    // The base class for HTTP error responses
    if (error instanceof errors.FactifyError) {
      console.log(error.message);
      console.log(error.httpMeta.response.status);
      console.log(error.httpMeta.response.headers);
      console.log(error.httpMeta.request);

      // Handle specific error types
      if (error instanceof errors.ErrorT) {
        console.log(error.data$.error);
      }
    }
  }
}

run();

Network Errors

The SDK provides specific error classes for network issues:
Error ClassDescription
ConnectionErrorUnable to connect to server
RequestTimeoutErrorRequest timed out
RequestAbortedErrorRequest was aborted
InvalidRequestErrorInvalid request input
ResponseValidationErrorResponse doesn’t match expected schema

Error Codes Reference

CodeDescription
missing_required_fieldRequired field not provided
invalid_field_valueField value fails validation
invalid_enum_valueValue not in allowed set
invalid_file_typeUploaded file not PDF
file_too_largeFile exceeds size limit
invalid_page_tokenPagination token invalid