{"_id":"@domotz/chaos-interceptor","_rev":"3-f7138a238253f36183a06efaa0690797","name":"@domotz/chaos-interceptor","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@domotz/chaos-interceptor","version":"2.0.0","keywords":["axios","chaos","xhr","http","ajax","promise","fetch","node"],"author":{"name":"Alessandro Pagiaro"},"license":"MIT","_id":"@domotz/chaos-interceptor@2.0.0","maintainers":[{"name":"domotz_apagiaro","email":"a.pagiaro@domotz.com"},{"name":"a.azzara","email":"a.azzara@domotz.com"},{"name":"massimiliano78","email":"mcuzzoli@domotz.com"},{"name":"iacopo_domotz","email":"iacopo@domotz.com"},{"name":"atondo","email":"atondo@domotz.com"}],"homepage":"https://github.com/domotz/chaos-interceptor","dist":{"shasum":"3acdc381c457b22189bbc6e319874b909dd2e0d0","tarball":"https://registry.npmjs.org/@domotz/chaos-interceptor/-/chaos-interceptor-2.0.0.tgz","fileCount":13,"integrity":"sha512-E893Rklt51y6mUGFS3n5EiwsfYwaKpF9VTna37qI6aG7WJpbTn5CHoTjTY40+trInQgxoVCsQVlG03lO3Qswrg==","signatures":[{"sig":"MEUCIGgVRkUOotkHPRM6wXKXs9AVO7x8npnxV1TKohWDX72IAiEAvB6vSfbcPSFW0D2qHnSsslOzulRRJz5P4Tez+5+CIRo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18051,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjf4TZACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqZnQ/9EqT5wOKhCF66SH3573x1ESMgnr52f9JyNYFq3kCkF+Vuj1xx\r\ndoI10S8jH74jui0pO7gGFOzkY085GZauCe4YENha92XgU6lRZ+KQgKeCc2nd\r\nNFib31bgt07rrIFlo8FpD6mgA2njk0n6y0X3J88HpN4phzJm8tb9BnR5s2Pr\r\nZ3BpNXLjB3J6tCuTml5VaYI4+zc/Nrocw6UR67jyvg1REtwsNI68DeUn/Mww\r\nstO8TMvQ/c/QugjTdTUYyaLmT4pBNWxk8y2oSvsRJzdpi+ljRCScshvFkEJw\r\nuYRXalmx+BFzQQG5Xg+DS7s9Afx5th6V67KjHG1FHx4r5Ofv8i6UrSis8ktN\r\n6t26J2eOFbqfYTq7ajUJIgoPkb/Rsbauju+NCdM+tcWDE2I9kiGPuY3+wdE6\r\nNB/qYuHUdahhpgoIEqkmz2c7qml19WTH1a11UKZgy1YPfZm6fAemWRnKFo5D\r\nCrEkxcPD7o5fuq73nUxhn06GX8P6EukI7LAS9PVHraQkw3RPMDNRgwzBE+m3\r\nVC0L5YNwwbkeLY8rzM0Bg0s4Tl1Sikg7uROLpQG6wz8MoXAplo90BfEvJgIG\r\nI79YQoB29PLF4DXu7VOCYbWi5rY9JLrFZzQRzJ8ZdqyceYHFtdcX+MHdxDOm\r\n31IN82Vm2Gq+BVwyzZ+IcavNpEqL9ChcUvk=\r\n=tBfd\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","types":"lib/types/index.d.ts","access":"public","gitHead":"4f1ee9421cf21893efb5b4a7d84af02a0b3ebbb0","scripts":{"test":"jest","build":"rm -rf ./dist && rm -rf ./lib && tsc","prepare":"tsc","test:watch":"jest --watchAll"},"_npmUser":{"name":"domotz_apagiaro","email":"a.pagiaro@domotz.com"},"_npmVersion":"6.14.17","description":"Inject chaos into your network layer. Randomize response.","directories":{},"_nodeVersion":"14.19.2","dependencies":{"axios":"^0.21.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^27.0.6","nock":"^13.1.1","ts-jest":"^27.0.3","typescript":"^4.3.5","@types/jest":"^26.0.24","@types/node":"^16.3.0"},"_npmOperationalInternal":{"tmp":"tmp/chaos-interceptor_2.0.0_1669301465163_0.1391185126046568","host":"s3://npm-registry-packages"}}},"time":{"created":"2022-11-24T14:51:05.099Z","modified":"2025-11-04T11:14:26.299Z","2.0.0":"2022-11-24T14:51:05.354Z"},"author":{"name":"Alessandro Pagiaro"},"license":"MIT","homepage":"https://github.com/domotz/chaos-interceptor","keywords":["axios","chaos","xhr","http","ajax","promise","fetch","node"],"description":"Inject chaos into your network layer. Randomize response.","maintainers":[{"email":"a.azzara@domotz.com","name":"a.azzara"},{"email":"mcuzzoli@domotz.com","name":"massimiliano78"},{"email":"atondo@domotz.com","name":"atondo"},{"email":"a.pagiaro@domotz.com","name":"domotz_apagiaro"},{"email":"alessandro.casella@domotz.com","name":"alessandro_casella_domotz"},{"email":"antonio.arena@domotz.com","name":"arena_domotz"}],"readme":"# chaos-interceptor\n\n<p align=\"center\">chaos-interceptor inject random errors into your network layer.</p>\n\n## Features\n\n🌪 Randomize response <br>\n⏱ Delay response\n\n## Usage\n\n### Basic Usage\n\n##### Javascript Fetch \nUse chaosInterceptor to random raise error on network request\n\n```ts\nimport {createChaosFetch} from '@domotz/chaos-interceptor';\n\nwindow.fetch = createChaosFetch();\n```\n\nthen\n\n```ts\ntry {\n  await fetch(\"http://api.github.com/\");\n} catch (error) {\n  // may happen fetch errors with random\n  console.log(error.status);\n  console.log(error.statusText);\n}\n```\n\n##### Apollo-Client \nYou can specify the `fetch` to use in `HttpLink` configuration object. \n\n```ts\nimport {createChaosFetch} from '@domotz/chaos-interceptor';\nimport { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';\n\nconst httpLink = new HttpLink({\n   uri: '/graphql',\n   fetch: createChaosFetch(simulatedErrors, {logError: true}),\n});\n\nconst client = new ApolloClient({\n  cache: new InMemoryCache(),\n  link: httpLink,\n});\n```\n\n##### Axios Fetch \nUse chaosInterceptor\n\n```ts\nimport {createChaosInterceptor} from '@domotz/chaos-interceptor';\n\nconst client = axios.create();\nconst chaosInterceptor = createChaosInterceptor();\nclient.interceptors.response.use(chaosInterceptor);\n```\n\nthen\n\n```ts\ntry {\n  await axios.get(\"http://api.github.com/\");\n} catch (error) {\n  // may happen AxiosError with random\n  console.log(error.status);\n  console.log(error.data);\n}\n```\n\n##### Possible outputs\n\nPossible `error.status` is one of following\n\n- 429\n- 500\n- 502\n- 503\n- 504\n\nPossible `error.statusText` is one of following\n\n- \"Too Many Requests\"\n- \"Internal Server Error\"\n- \"Bad Gateway\"\n- \"Service Unavailable\"\n- \"Gateway Timeout\"\n\n### Params\n\nSpecify the response that will result in an error\n\n```ts\nconst chaosFetch = createChaosFetch([\n  {\n    status: 500,\n    body: {\n      message: \"Internal Server Error\",\n    },\n    delay: 500, // delay response (ms)\n    rate: 10, // possibilities (%)\n  },\n  {\n    status: 504,\n    body: {\n      message: \"Gateway Timeout\",\n    },\n    delay: 100000,\n    rate: 20,\n  },\n]);\n```\n\nPossible `error.status` is one of following\n\n- 500\n- 504\n\nPossible `error.statusText` is one of following\n\n- `{ message: \"Internal Server Error\" }`\n- `{ message: \"Gateway Timeout\" }`\n\n\nWith `{showError: true}` it console.log a message everytime a response is rejected\n","readmeFilename":"README.md"}