{"id":47670,"library":"fetchres","title":"fetchres","description":"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.","status":"maintenance","version":"1.7.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install fetchres","lang":"bash","label":"npm"},{"cmd":"yarn add fetchres","lang":"bash","label":"yarn"},{"cmd":"pnpm add fetchres","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default import only; named import will be undefined.","wrong":"import { fetchres } from 'fetchres';","symbol":"fetchres","correct":"import fetchres from 'fetchres';"},{"note":"CommonJS requires the default export.","wrong":"const { fetchres } = require('fetchres');","symbol":"require('fetchres')","correct":"const fetchres = require('fetchres');"},{"note":"Error classes are properties on the default export.","wrong":"import { BadServerResponseError } from 'fetchres';","symbol":"BadServerResponseError","correct":"import fetchres from 'fetchres'; const err = new fetchres.BadServerResponseError();"}],"quickstart":{"code":"// Must have fetch and Promise available (e.g., via polyfill)\nimport fetchres from 'fetchres';\n\nfetch('https://api.example.com/data.json')\n  .then(fetchres.json)\n  .then(data => {\n    console.log('Parsed JSON:', data);\n  })\n  .catch(err => {\n    if (err.name === 'BadServerResponseError') {\n      console.error('Server error status:', err.message);\n    } else if (err.name === 'InvalidJsonError') {\n      console.error('Invalid JSON in response body');\n    } else {\n      console.error('Network or other error:', err);\n    }\n  });","lang":"javascript","description":"Demonstrates using fetchres.json to parse a JSON response and handle specific error types."},"warnings":[{"fix":"Install a fetch polyfill (e.g., 'whatwg-fetch') and Promise polyfill (e.g., 'es6-promise') and import them before fetchres.","message":"fetchres does not include fetch or Promise polyfills; you must provide your own in environments without native support (e.g., older browsers, Node.js <18).","severity":"gotcha","affected_versions":"all"},{"fix":"Always pass the result of fetch() (a Response object) to fetchres methods.","message":"fetchres.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.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider wrapping with type annotations or migrating to a typed alternative (e.g., ky).","message":"The package uses ES5/CommonJS and does not publish TypeScript type definitions; users must create their own .d.ts or rely on inferred types.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"search_vec":"'1.7.2':21 'api':10 'badserverresponseerror':55 'browser':45 'bundl':30 'common':12 'current':23 'custom':52 'differenti':49 'e.g':42 'error':19,53,61 'expos':51 'fetch':9,33 'fetchr':1,2 'fine':59 'fine-grain':58 'grain':60 'handl':18,62 'handler':5 'invalidjsonerror':56 'javascript':68 'json':16 'key':48 'like':14 'must':39 'nativ':65 'node.js':47 'object':67 'older':44 'pars':15 'pattern':13 'polyfil':36 'promis':35 'provid':3 'recent':25 'releas':26 'respons':4,66 'simplifi':11 'suppli':40 'type':54 'user':38 'util':6 'version':20 'versus':63","created_at":"2026-06-07T16:52:41.776545+00:00","updated_at":"2026-06-07T16:52:41.776545+00:00","problems":[{"fix":"Use default import: import fetchres from 'fetchres' then fetchres.json, or require: const fetchres = require('fetchres').","cause":"fetchres.json is a function on the import, but if the import is wrong (e.g., destructuring named export) it becomes undefined.","error":"fetchres.json is not a function"},{"fix":"Chain fetch with .then(response => fetchres.json(response)) or use .then(fetchres.json) on the fetch promise.","cause":"Passing a Promise (result of fetch without .then) instead of the Response object to fetchres methods.","error":"Uncaught TypeError: Cannot read properties of undefined (reading 'json')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"fetchres","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}