Registry / testing / fetch-error

fetch-error

JSON →
library1.0.0jsnpmunverified

A specialized error class for the Fetch API, wrapping HTTP error responses with status code, status text, and optional response object. Version 1.0.0 stable, maintained on a semantic versioning cadence. Unlike generic Error, it allows instanceof checks and carries structured error info. Designed to pair with fetch() for clean error handling.

npm install fetch-error
INSTALL
IMPORT
SIG · FETCH-ERROR
F
fetch-error
testingjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FetchError
import FetchError from 'fetch-error'
const { FetchError } = require('fetch-error')
ESM default import. The package does not export named exports.
FetchError (CommonJS)
const FetchError = require('fetch-error')
const { default: FetchError } = require('fetch-error')
CommonJS require returns the constructor directly.
TypeScript (no types shipped)
// @ts-ignore const FetchError = require('fetch-error')
import FetchError from 'fetch-error'
No type declarations; use @ts-ignore or declare module.

Demonstrates creating a FetchError from an HTTP response and catching it with instanceof to distinguish from network errors.

const FetchError = require('fetch-error'); async function fetchWithError(url) { const res = await fetch(url); if (!res.ok) { throw new FetchError(res.status, res.statusText, { response: res }); } return res.json(); } fetchWithError('https://api.example.com/data') .then(data => console.log(data)) .catch(err => { if (err instanceof FetchError) { console.error('HTTP Error:', err.statusCode, err.message); } else { console.error('Network Error:', err); } });
Debug
Known issues
gotchaFetchError is not a subclass of Error? Check instanceof Error?
fix
It extends Error, so instanceof Error works, but custom error properties (statusCode, statusText) are not standard.
affects: >=1.0.0
gotchaThe `response` option passed to constructor is not copied or cloned; it's stored by reference.
fix
Be aware that modifying the response object later will affect the error.
affects: >=1.0.0
deprecatedPackage may be lightly maintained; consider using native Error or a more modern alternative.
fix
No known deprecations; but library ecosystem around Fetch API errors is limited.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: fetch_error_1.default is not a constructor
Using named import instead of default import in ESM.
fix
Use `import FetchError from 'fetch-error'` (not `{ FetchError }`).
FetchError is not defined
Trying to use FetchError without importing it, or using wrong import syntax.
fix
Require it: `const FetchError = require('fetch-error')` or default import.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fetch-error — npm install fetch-error · libregistry