Renta Docs

SDK Error Handling

Typed exceptions, automatic retries, and error recovery patterns.

The Renta SDK throws typed exceptions for all API errors, making it easy to handle specific failure cases.

Error Classes

import {
  RentaError,           // Base class
  RentaAuthError,       // 401, 403
  RentaNotFoundError,   // 404
  RentaValidationError, // 400, 422
  RentaConflictError,   // 409
  RentaRateLimitError,  // 429
  RentaInternalError,   // 500+
} from '@renta/sdk';

Catching Errors

try {
  await renta.bookings.create({
    customer_id: 'cust_abc',
    pickup_date: '2026-07-01T09:00:00Z',
    return_date: '2026-07-03T17:00:00Z',
    line_items: [{ fleet_item_id: 'fi_nonexistent' }],
  });
} catch (err) {
  if (err instanceof RentaValidationError) {
    // Field-level errors
    for (const fieldErr of err.errors) {
      console.log(`${fieldErr.field}: ${fieldErr.message}`);
    }
  } else if (err instanceof RentaNotFoundError) {
    console.log(`Not found: ${err.message}`);
    console.log(`Request ID: ${err.requestId}`);
  } else if (err instanceof RentaConflictError) {
    console.log(`Conflict: ${err.message}`);
    // e.g., double booking, item has active bookings
  } else if (err instanceof RentaRateLimitError) {
    console.log(`Rate limited. Retry after ${err.retryAfter}s`);
  } else if (err instanceof RentaAuthError) {
    console.log('Invalid API key or insufficient scope');
  } else if (err instanceof RentaInternalError) {
    console.log('Server error — auto-retried and still failed');
  }
}

Error Properties

All errors extend RentaError:

PropertyTypeDescription
messagestringHuman-readable error message
typestringError type identifier
statusnumberHTTP status code
requestIdstring?Unique request ID (for support)

RentaValidationError adds:

PropertyTypeDescription
errorsArray<{field, message}>Field-level validation errors

RentaRateLimitError adds:

PropertyTypeDescription
retryAfternumberSeconds to wait before retrying

Automatic Retries

The SDK automatically retries on these conditions:

ConditionBehavior
429 Rate LimitedRespects Retry-After header, exponential backoff
5xx Server ErrorExponential backoff with jitter, capped at 30s

Default configuration: 3 retries with 1-second base delay.

// Custom retry configuration
const renta = new Renta({
  apiKey: process.env.RENTA_API_KEY!,
  maxRetries: 5,     // More retries
  retryDelay: 2000,  // Longer base delay
});

// Disable retries entirely
const renta = new Renta({
  apiKey: process.env.RENTA_API_KEY!,
  maxRetries: 0,
});

Production Error Handling Pattern

import { Renta, RentaError } from '@renta/sdk';

const renta = new Renta({
  apiKey: process.env.RENTA_API_KEY!,
  logger: {
    error: (msg, meta) => {
      // Send to your error tracking service
      Sentry.captureMessage(msg, { extra: meta });
    },
  },
});

async function createBookingSafe(params: CreateBookingInput) {
  try {
    return await renta.bookings.create(params);
  } catch (err) {
    if (err instanceof RentaError) {
      // Log with request ID for debugging
      console.error(`Renta API error [${err.requestId}]: ${err.message}`);

      // Re-throw typed errors for the caller to handle
      throw err;
    }
    // Unknown error
    throw new Error('Unexpected error creating booking');
  }
}