{"name":"@fastify/error","version":"4.0.0","description":"A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.","main":"index.js","type":"commonjs","types":"types/index.d.ts","scripts":{"lint":"standard","lint:fix":"standard --fix","test":"npm run test:unit && npm run test:typescript","test:unit":"tap","test:typescript":"tsd"},"repository":{"type":"git","url":"git+https://github.com/fastify/fastify-error.git"},"keywords":["fastify","error","utility","plugin"],"author":{"name":"Tomas Della Vedova"},"license":"MIT","bugs":{"url":"https://github.com/fastify/fastify-error/issues"},"homepage":"https://github.com/fastify/fastify-error#readme","devDependencies":{"benchmark":"^2.1.4","standard":"^17.1.0","tap":"^18.7.1","tsd":"^0.31.0"},"tsd":{"compilerOptions":{"esModuleInterop":true}},"publishConfig":{"access":"public"},"_id":"@fastify/error@4.0.0","gitHead":"316bebea2b8625ba7974376202950e86cef5bcfa","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-OO/SA8As24JtT1usTUTKgGH7uLvhfwZPwlptRi2Dp5P4KKmJI3gvsZ8MIHnNwDs4sLf/aai5LzTyl66xr7qMxA==","shasum":"7842d6161fbce78953638318be99033a0c2d5070","tarball":"http://registry-npm.ywwl.com/@fastify/error/download/@fastify/error-4.0.0.tgz","fileCount":15,"unpackedSize":18464,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCSH9b/bRoqp7B8zFIt9hxkQK9y9ccJHJ5q1ThiWC1jRAIhANN3xue9cItcGMwCHyc4rkAeiv8NVAJfs4jbqWE/hnks"}],"size":4781,"noattachment":false,"key":"/@fastify/error/-/@fastify/error-4.0.0.tgz"},"_npmUser":{"name":"jsumners","email":"james.sumners@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/error_4.0.0_1718999240861_0.650744188107683"},"_hasShrinkwrap":false,"readme":"# @fastify/error\n\n![CI](https://github.com/fastify/fastify-error/workflows/CI/badge.svg)\n[![NPM version](https://img.shields.io/npm/v/@fastify/error.svg?style=flat)](https://www.npmjs.com/package/@fastify/error)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nA small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.\n\n### Install\n```\nnpm i @fastify/error\n```\n\n### Usage\n\nThe module exports a function that you can use for consistent error objects, it takes 4 parameters:\n\n```\ncreateError(code, message [, statusCode [, Base]])\n```\n\n- `code` (`string`, required) - The error code, you can access it later with `error.code`. For consistency, we recommend prefixing plugin error codes with `FST_`\n- `message` (`string`, required) - The error message. You can also use interpolated strings for formatting the message.\n- `statusCode` (`number`, optional) - The status code that Fastify will use if the error is sent via HTTP.\n- `Base` (`ErrorConstructor`, optional) - The base error object that will be used. (eg `TypeError`, `RangeError`)\n\n```js\nconst createError = require('@fastify/error')\nconst CustomError = createError('ERROR_CODE', 'Hello')\nconsole.log(new CustomError()) // error.message => 'Hello'\n```\n\nHow to use an interpolated string:\n```js\nconst createError = require('@fastify/error')\nconst CustomError = createError('ERROR_CODE', 'Hello %s')\nconsole.log(new CustomError('world')) // error.message => 'Hello world'\n```\n\nHow to add cause:\n```js\nconst createError = require('@fastify/error')\nconst CustomError = createError('ERROR_CODE', 'Hello %s')\nconsole.log(new CustomError('world', {cause: new Error('cause')})) \n// error.message => 'Hello world'\n// error.cause => Error('cause')\n```\n\n### TypeScript\n\nIt is possible to limit your error constructor with a generic type using TypeScript:\n\n```ts\nconst CustomError = createError<[string]>('ERROR_CODE', 'Hello %s')\nnew CustomError('world')\n//@ts-expect-error\nnew CustomError(1)\n```\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","publish_time":1718999241045,"maintainers":[{"name":"gurgunday","email":"hey@gurgun.day"},{"name":"metcoder95","email":"me@metcoder.dev"},{"name":"galvez","email":"jonasgalvez@gmail.com"},{"name":"simenb","email":"sbekkhus91@gmail.com"},{"name":"coopflow","email":"community@coopflow.com"},{"name":"simoneb","email":"simone.busoli@gmail.com"},{"name":"rafaelgss","email":"rafael.nunu@hotmail.com"},{"name":"starptech","email":"deusdustin@gmail.com"},{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"allevo","email":"tomallevi@gmail.com"},{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"zekth","email":"vince.legoff@gmail.com"},{"name":"eomm","email":"behemoth89@gmail.com"},{"name":"fox1t","email":"maksim@sinik.it"},{"name":"airhorns","email":"harry@harry.me"},{"name":"kibertoad","email":"iselwin@gmail.com"},{"name":"climba03003","email":"kaka@kakawebsitedemo.com"}],"_cnpm_publish_time":1718999241045,"dist-tags":{"latest":"4.2.1"}}