Docs

Guides

TypeScript SDK

Response metadata, errors, maintenance windows and the browser safeguard of @tilt-pay/sdk.

@tilt-pay/sdk is the typed client of the API. Installation is described in the quickstart.

Response metadata#

lastResponse(result) returns what came with the response a result was built from: HTTP status, requestId, rate limit, number of attempts and whether it is a replay of an idempotent request.

TypeScript
import { TiltPay, lastResponse } from '@tilt-pay/sdk'

const tilt = new TiltPay(process.env.TILT_PAY_API_KEY!)
const user = await tilt.users.retrieve('4821')
console.log(lastResponse(user)?.requestId, lastResponse(user)?.rateLimit.remaining)

Package 0.1.0-rc.1 does not attach this metadata to lists (list() and getNextPage()); later versions do.

Errors and retries#

Every failure is a TiltPayError with status, code, param and requestId: branch on code, never on message. Network errors, timeouts, 408, 429, 5xx and 409 idempotency_in_progress are retried automatically (2 times by default). See Errors.

Maintenance windows#

During a maintenance window the API answers 503 maintenance_mode. The SDK throws a MaintenanceError with retryAfterSeconds. It waits and retries by itself when that delay is 60 seconds or less; beyond that the error reaches your code, which should try again later.

TypeScript
import { MaintenanceError } from '@tilt-pay/sdk'

try {
  await tilt.users.create({ phone: '+33612345678' })
} catch (error) {
  if (error instanceof MaintenanceError) console.log('retry in', error.retryAfterSeconds, 'seconds')
  else throw error
}

Never in a browser#

A secret key must never reach a browser. The constructor throws a ConfigurationError when it detects one. dangerouslyAllowBrowser: true lifts the safeguard, for a throwaway sandbox demo only. In a web page, use the signup component, which talks to your own backend.