Nuclom Docs
API Reference

API Error Codes

This document describes the standardized error response format and error codes used by the Nuclom API.

API Error Codes

This document describes the standardized error response format and error codes used by the Nuclom API.

Error Response Format

All API errors follow a consistent JSON structure:

{
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error message",
    "details": {
      // Optional additional context
    }
  }
}

Error Code Categories

Error codes follow the format CATEGORY_SPECIFIC_ERROR:

CategoryDescription
AUTHAuthentication & authorization
VALIDATIONInput validation
NOT_FOUNDResource not found
CONFLICTDuplicate/conflict errors
STORAGEFile storage
VIDEOVideo processing
BILLINGPayment & subscription
DATABASEDatabase operations
INTERNALInternal server errors

Authentication Errors (401, 403)

CodeHTTP StatusDescription
AUTH_UNAUTHORIZED401User is not authenticated
AUTH_FORBIDDEN403User lacks permission
AUTH_SESSION_EXPIRED401Session has expired
AUTH_SESSION_INVALID401Session is invalid or corrupted

Example Response

{
  "error": {
    "code": "AUTH_UNAUTHORIZED",
    "message": "Authentication required"
  }
}

Validation Errors (400)

CodeHTTP StatusDescriptionDetails
VALIDATION_FAILED400General validation failurefields: Array of errors
VALIDATION_MISSING_FIELD400Required field is missingfield: Field name
VALIDATION_INVALID_FORMAT400Invalid input format-

Example Response

{
  "error": {
    "code": "VALIDATION_MISSING_FIELD",
    "message": "Title is required",
    "details": {
      "field": "title"
    }
  }
}

Not Found Errors (404)

CodeHTTP StatusDescriptionDetails
NOT_FOUND_RESOURCE404Generic resource not foundentity, id
NOT_FOUND_VIDEO404Video not foundentity: "video", id
NOT_FOUND_USER404User not foundentity: "user", id
NOT_FOUND_ORGANIZATION404Organization not foundentity: "organization", id
NOT_FOUND_SERIES404Series not foundentity: "series", id
NOT_FOUND_PLAN404Billing plan not foundentity: "plan", id

Example Response

{
  "error": {
    "code": "NOT_FOUND_VIDEO",
    "message": "Video not found",
    "details": {
      "entity": "video",
      "id": "video_123"
    }
  }
}

Conflict Errors (409)

CodeHTTP StatusDescriptionDetails
CONFLICT_DUPLICATE409Duplicate entryentity, field
CONFLICT_ALREADY_EXISTS409Resource already exists-

Example Response

{
  "error": {
    "code": "CONFLICT_DUPLICATE",
    "message": "A video with this title already exists",
    "details": {
      "entity": "video",
      "field": "title"
    }
  }
}

Storage Errors (500, 503)

CodeHTTP StatusDescription
STORAGE_NOT_CONFIGURED503Storage service unavailable
STORAGE_UPLOAD_FAILED500File upload failed
STORAGE_DELETE_FAILED500File deletion failed
STORAGE_URL_GENERATION_FAILED500Failed to generate URL

Video Processing Errors (400, 500)

CodeHTTP StatusDescriptionDetails
VIDEO_UNSUPPORTED_FORMAT400Unsupported video formatformat, supportedFormats
VIDEO_FILE_TOO_LARGE400File exceeds size limitfileSize, maxSize
VIDEO_PROCESSING_FAILED500Processing failedstage: processing stage

Example Response

{
  "error": {
    "code": "VIDEO_FILE_TOO_LARGE",
    "message": "File size exceeds the maximum limit of 500MB",
    "details": {
      "fileSize": 536870912,
      "maxSize": 524288000
    }
  }
}

Billing Errors (400, 402, 403)

CodeHTTP StatusDescriptionDetails
BILLING_NOT_CONFIGURED503Billing service unavailable-
BILLING_PAYMENT_FAILED402Payment failed-
BILLING_PLAN_LIMIT_EXCEEDED403Plan limit reachedresource, currentUsage, limit
BILLING_NO_SUBSCRIPTION403No active subscription-
BILLING_WEBHOOK_INVALID400Invalid webhook signature-
BILLING_STRIPE_ERROR500Stripe API error-

Example Response

{
  "error": {
    "code": "BILLING_PLAN_LIMIT_EXCEEDED",
    "message": "You have reached your storage limit",
    "details": {
      "resource": "storage",
      "currentUsage": 10737418240,
      "limit": 10737418240
    }
  }
}

Database Errors (500)

CodeHTTP StatusDescription
DATABASE_ERROR500Database query failed
DATABASE_TRANSACTION_FAILED500Transaction failed

Internal Errors (500)

CodeHTTP StatusDescription
INTERNAL_ERROR500Unexpected internal error
INTERNAL_CONFIGURATION_ERROR500Configuration error
INTERNAL_AI_SERVICE_ERROR500AI service error

Client-Side Error Handling

When handling errors in the client, use the error code to provide appropriate user feedback:

import { type ApiErrorResponse, getErrorMessage, ErrorCodes } from "@/lib/api-errors";

async function handleApiResponse(response: Response) {
  if (!response.ok) {
    const data: ApiErrorResponse = await response.json();
    const code = data.error.code;

    // Handle specific errors
    switch (code) {
      case ErrorCodes.AUTH_UNAUTHORIZED:
        // Redirect to login
        window.location.href = "/login";
        break;
      case ErrorCodes.BILLING_PLAN_LIMIT_EXCEEDED:
        // Show upgrade modal
        showUpgradeModal(data.error.details);
        break;
      default:
        // Show generic error message
        toast.error(getErrorMessage(code));
    }
  }
}

HTTP Status Code Summary

StatusMeaningCommon Error Codes
400Bad RequestVALIDATION_*, VIDEO_UNSUPPORTED_FORMAT
401UnauthorizedAUTH_UNAUTHORIZED, AUTH_SESSION_*
402Payment RequiredBILLING_PAYMENT_FAILED
403ForbiddenAUTH_FORBIDDEN, BILLING_PLAN_LIMIT_*
404Not FoundNOT_FOUND_*
409ConflictCONFLICT_*
500Internal Server ErrorDATABASE_, INTERNAL_, STORAGE_*
503Service Unavailable*_NOT_CONFIGURED