ICBucket
ICBucketv1.0
Overview
  • Introduction
  • Quick Start
  • Installation
Guides
  • Configuration
  • Authentication
  • Basic Usage
  • Best Practices
API Reference
  • API Overview
  • API Endpoints
  • API Requests
  • API Responses
Errors
  • Error Codes
  • Error Handling
  • Troubleshooting
Deployment
  • Local Development
  • Production Deployment
Reference
  • Configuration Reference
  • Types Reference
  • Changelog
FAQ
  • Frequently Asked Questions
PricingGitLabNew bucket
  1. ICBucket
  2. Errors
  3. Error Handling

Error Handling

Implement resilient client-side retry strategies, exponential backoff, and exception catching.

Error Handling

Build production-grade applications with resilient network retry handling and typed error catching.

Prerequisites#

  • Client configured with error interception.

Steps#

1. Typed Exception Catching#

The TypeScript SDK provides typed errors for granular recovery:

import { ICBucket, BucketError } from "icpay-bucket"

const bucket = new ICBucket({
  bucketId: "my-assets",
  apiKey: process.env.ICBUCKET_API_KEY!,
})

try {
  await bucket.uploadFile("document.pdf", buffer)
} catch (error) {
  if (error instanceof BucketError) {
    switch (error.code) {
      case "ERR_PAYLOAD_TOO_LARGE":
        console.warn("File is too large for single-call upload, switching to chunked upload...")
        await bucket.uploadLargeFile("document.pdf", buffer)
        break
      case "ERR_QUOTA_EXCEEDED":
        console.error("Storage limit reached! Please upgrade your tier.")
        break
      default:
        console.error(`Bucket error [${error.code}]:`, error.message)
    }
  } else {
    console.error("Unexpected error:", error)
  }
}

2. Exponential Backoff Pattern#

When handling transient network fluctuations or canister busy states:

async function uploadWithRetry(fn: () => Promise<any>, maxAttempts = 3) {
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
    try {
      return await fn()
    } catch (err: any) {
      if (attempt === maxAttempts || !err.isRetryable) throw err
      const delay = Math.pow(2, attempt) * 500
      await new Promise((resolve) => setTimeout(resolve, delay))
    }
  }
}

Related Pages#

  • Error Codes
  • Troubleshooting
  • Configuration Reference
PreviousError CodesNextTroubleshooting
Edit this page on GitLabUpdated recently

On this page

PrerequisitesSteps1. Typed Exception Catching2. Exponential Backoff PatternRelated Pages

Search documentation

Quickly find guides, APIs, and reference docs