@polyweave/errors (1.0.2)
Installation
@polyweave:registry=https://hub.kl1.tenere.ai/api/packages/Polyweave/npm/npm install @polyweave/errors@1.0.2"@polyweave/errors": "1.0.2"About this package
errors
Standardized error codes and helpers for Polyweave.
Synopsis
import { ErrorCode, normalizeErrorCode, mapHttpStatusToErrorCode } from '@polyweave/errors';
const code = normalizeErrorCode('RATE_LIMITED');
console.log(code === ErrorCode.RATE_LIMIT_EXCEEDED); // true
Install
npm install @polyweave/errors
API
ErrorCode
Re-exported from @polyweave/core. Enum of standard Polyweave error codes including RATE_LIMIT_EXCEEDED, QUEUE_TIMEOUT, INVALID_INPUT, AUTHENTICATION_ERROR, AUTHORIZATION_ERROR, SERVICE_UNAVAILABLE, PROVIDER_ERROR, PROTOCOL_ERROR, ADAPTER_ERROR, and more.
normalizeErrorCode(code)
Accepts a raw error code string, an alias, or an ErrorCode value and returns the canonical ErrorCode. Returns ErrorCode.ADAPTER_ERROR for unknown or falsy input.
normalizeRateLimit(rateLimit)
Accepts a rate limit object from a provider response. Strips null/undefined fields and returns the cleaned object, or null if empty.
parseRetryAfterSeconds(value)
Accepts a string or number (e.g. HTTP Retry-After header) and returns the delay in seconds as a number. Supports date strings and numeric values.
buildErrorMetadata(options)
Builds a metadata object for PolyweaveError. Accepts { provider, statusCode, errorType, errorCode, originalFrameType, rateLimit, retryAfterSeconds, requestId, originalError, providerError, retryable }.
mapHttpStatusToErrorCode(status)
Maps an HTTP status code to the corresponding ErrorCode. Handles 400, 401, 403, 404, 408, 409, 422, 429, 500, 502, 503, 504, 529.
isRetryableErrorCode(code)
Returns true if the given error code represents a transient failure suitable for automatic retry.
Tests
npm test
Requirements
Node.js 18 or later. ESM only.
License
MIT
Dependencies
Development Dependencies
| ID | Version |
|---|---|
| @rigor/core | * |
Peer Dependencies
| ID | Version |
|---|---|
| @polyweave/core | ^1.0.0 |