Adapters
Adapters are the detection and normalization layer. Each adapter knows how to recognize a specific error shape and extract its fields into a NormalizedError.
Default adapter chain
When you call normalizeError without specifying adapters, the default chain runs in this order. The first adapter whose canHandle returns true wins.
// Default adapter chain (used when options.adapters is omitted): [axiosAdapter, kyAdapter, fetchAdapter, apolloAdapter, nodeHttpAdapter, genericAdapter]
Adapter priority
Built-in adapters
Expand each adapter below to see its detection logic, handled error shapes, and example output.
Handles errors thrown by Axios. Detects AxiosError instances by checking isAxiosError, the error name, or the presence of config + request/response properties.
Detection rules
isAxiosError === truename === "AxiosError"Has config + (request or response)
Example output
| Field | Example value |
|---|---|
| code | HTTP_503 |
| message | Service unavailable. Please retry shortly. |
| status | 503 |
| retryable | true |
| details | { url: "/api/data", method: "get", ... } |
Handles HTTPError and TimeoutError thrown by ky. Detects by checking the error name or the presence of response + request + options.
Detection rules
name === "HTTPError" or "TimeoutError"Has response + request + options
Example output
| Field | Example value |
|---|---|
| code | HTTP_503 |
| message | Service Unavailable |
| status | 503 |
| retryable | true |
| details | { url: "/api/data", ... } |
Handles native fetch Response objects and fetch-related errors. Detects Response-like objects (status + statusText/url) and TypeError/AbortError from fetch.
Detection rules
Has status + (statusText or url)name === "AbortError" or "TypeError""fetch" in error messageError with cause.code
Example output
| Field | Example value |
|---|---|
| code | HTTP_503 |
| message | Service Unavailable |
| status | 503 |
| retryable | true |
| details | { url: "http://localhost/api/data", statusText: "Service Unavailable" } |
Handles Apollo Client errors and GraphQL error shapes. Detects by checking for graphQLErrors, networkError, or the ApolloError name.
Detection rules
Has graphQLErrors arrayHas networkErrorname === "ApolloError"
Example output
| Field | Example value |
|---|---|
| code | TOO_MANY_REQUESTS |
| message | Quota exhausted |
| status | 502 |
| retryable | true |
| details | { graphQLErrors: [...], networkError: { ... } } |
Handles Node.js transport-level errors such as connection resets, timeouts, and DNS failures. Detects Error instances whose code matches known Node network error codes.
Detection rules
Error with code in ECONNRESET, ECONNABORTED, ETIMEDOUT, EAI_AGAIN, ENOTFOUND, ECONNREFUSED, EHOSTUNREACH, EPIPEError with code starting with UND_ERR_
Example output
| Field | Example value |
|---|---|
| code | ECONNRESET |
| message | socket hang up |
| status | null |
| retryable | true |
| details | { syscall: "read" } |
Catches everything else. Handles plain Error instances, strings, and arbitrary objects. Always returns true from canHandle, so it should be last in any custom chain.
Detection rules
canHandle always returns true
Example output
| Field | Example value |
|---|---|
| code | UNKNOWN_ERROR |
| message | database connection dropped |
| status | null |
| retryable | false |
| details | null |
Custom adapter chains
Override the default chain by passing your own adapter array. This lets you add domain-specific adapters, remove adapters you don't need, or reorder the chain.
import {
normalizeError,
axiosAdapter,
fetchAdapter,
genericAdapter
} from "@npmforge/statusforge";
// Only keep adapters you need, in your preferred order
const result = normalizeError(error, {
adapters: [axiosAdapter, fetchAdapter, genericAdapter]
});Best practices
Need the full API?