Registry / testing / fetchres

fetchres

JSON →
library1.7.2jsnpmunverified

fetchres provides response handler utilities for the Fetch API, simplifying common patterns like parsing JSON and handling errors. Version 1.7.2 is current; no recent releases. It does not bundle its own fetch or Promise polyfills, so users must supply them (e.g., for older browsers or Node.js). Key differentiator: it exposes custom error types (BadServerResponseError, InvalidJsonError) for fine-grained error handling versus the native Response object.

npm install fetchres
INSTALL
IMPORT
SIG · FETCHRES
F
fetchres
testingjavascriptv1.7.2
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.

fetchres
✓ import fetchres from 'fetchres';
✗ import { fetchres } from 'fetchres';
Default import only; named import will be undefined.
require('fetchres')
✓ const fetchres = require('fetchres');
✗ const { fetchres } = require('fetchres');
CommonJS requires the default export.
BadServerResponseError
✓ import fetchres from 'fetchres'; const err = new fetchres.BadServerResponseError();
✗ import { BadServerResponseError } from 'fetchres';
Error classes are properties on the default export.

Demonstrates using fetchres.json to parse a JSON response and handle specific error types.

// Must have fetch and Promise available (e.g., via polyfill) import fetchres from 'fetchres'; fetch('https://api.example.com/data.json') .then(fetchres.json) .then(data => { console.log('Parsed JSON:', data); }) .catch(err => { if (err.name === 'BadServerResponseError') { console.error('Server error status:', err.message); } else if (err.name === 'InvalidJsonError') { console.error('Invalid JSON in response body'); } else { console.error('Network or other error:', err); } });
Debug
Known issues
gotchafetchres does not include fetch or Promise polyfills; you must provide your own in environments without native support (e.g., older browsers, Node.js <18).
fix
Install a fetch polyfill (e.g., 'whatwg-fetch') and Promise polyfill (e.g., 'es6-promise') and import them before fetchres.
affects: all
gotchafetchres.json expects a Response object with a json() method; passing a non-Response value (e.g., a promise) will fail silently or throw unexpected errors.
fix
Always pass the result of fetch() (a Response object) to fetchres methods.
affects: all
deprecatedThe package uses ES5/CommonJS and does not publish TypeScript type definitions; users must create their own .d.ts or rely on inferred types.
fix
Consider wrapping with type annotations or migrating to a typed alternative (e.g., ky).
affects: all
Errors
Common errors & fixes
fetchres.json is not a function
fetchres.json is a function on the import, but if the import is wrong (e.g., destructuring named export) it becomes undefined.
fix
Use default import: import fetchres from 'fetchres' then fetchres.json, or require: const fetchres = require('fetchres').
Uncaught TypeError: Cannot read properties of undefined (reading 'json')
Passing a Promise (result of fetch without .then) instead of the Response object to fetchres methods.
fix
Chain fetch with .then(response => fetchres.json(response)) or use .then(fetchres.json) on the fetch promise.
Upgrade
Version history
1.7.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
fetchres — npm install fetchres · libregistry