Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Error Handling

Handle errors that may occur during SDK operations.

Error Types

import { Pinner, PinnerError } from "@lumeweb/pinner"; const pinner = new Pinner({ jwt: "YOUR_API_TOKEN" }); try { const result = await pinner.upload(file); } catch (error) { if (error instanceof PinnerError) { console.error("Code:", error.code); console.error("Message:", error.message); console.error("Retryable:", error.retryable); console.error("Cause:", error.cause); } }

Error Properties

All PinnerError instances include:

PropertyTypeDescription
codestringUnique error code for programmatic handling
messagestringHuman-readable error description
retryablebooleanWhether the operation can be retried
cause`Errorundefined`
namestringError class name

Error Classes

Error ClassCodeRetryableDescription
PinnerErrorVariousVariesBase error class for all Pinner errors
ConfigurationErrorCONFIGURATION_ERRORNoInvalid SDK configuration
AuthenticationErrorAUTHENTICATION_ERRORNoInvalid or expired API token
UploadErrorUPLOAD_ERRORVariesBase class for upload errors
NetworkErrorNETWORK_ERRORYesNetwork connectivity issue
ValidationErrorVALIDATION_ERRORNoInvalid input or validation failure
EmptyFileErrorEMPTY_FILE_ERRORNoAttempted to upload empty file
TimeoutErrorTIMEOUT_ERRORYesRequest timed out
PinErrorPIN_ERRORVariesPin operation failed
NotFoundErrorNOT_FOUNDNoContent not found
RateLimitErrorRATE_LIMIT_EXCEEDEDYesToo many requests
EnvironmentErrorENVIRONMENT_ERRORNoUnsupported environment (e.g., missing required APIs)

RateLimitError Properties

try {
  await pinner.upload(file);
} catch (error) {
  if (error instanceof RateLimitError) {
    console.error("Rate limited, retry after:", error.retryAfter, "seconds");
  }
}

Common Error Codes

CodeDescription
CONFIGURATION_ERRORInvalid SDK configuration
AUTHENTICATION_ERRORInvalid or expired API token
UPLOAD_ERRORUpload failed
NETWORK_ERRORNetwork connectivity issue
VALIDATION_ERRORInvalid input or validation failure
EMPTY_FILE_ERRORCannot upload empty file
TIMEOUT_ERRORRequest timed out
PIN_ERRORPin operation failed
NOT_FOUNDContent not found
RATE_LIMIT_EXCEEDEDToo many requests
ENVIRONMENT_ERRORUnsupported environment

Retry Strategies

import { Pinner, isRetryable } from "@lumeweb/pinner"; async function uploadWithRetry(file, maxRetries = 3) { let lastError; for (let attempt = 1; attempt <= maxRetries; attempt++) { try { return await pinner.upload(file); } catch (error) { lastError = error; if (!isRetryable(error)) { throw error; } console.log(`Retry attempt ${attempt}/${maxRetries}`); await new Promise(r => setTimeout(r, 1000 * attempt)); } } throw lastError; }

Handling Network Errors

import { Pinner, NetworkError } from "@lumeweb/pinner"; const pinner = new Pinner({ jwt: "YOUR_API_TOKEN" }); try { const result = await pinner.upload(file); } catch (error) { if (error instanceof NetworkError) { console.error("Network error. Check your connection."); return; } throw error; }