{"id":17498293,"url":"https://github.com/simonepri/restify-errors-thrower","last_synced_at":"2025-06-11T19:36:05.826Z","repository":{"id":66098999,"uuid":"53504326","full_name":"simonepri/restify-errors-thrower","owner":"simonepri","description":"💥 Throw Restify errors easily!","archived":false,"fork":false,"pushed_at":"2018-01-08T13:52:45.000Z","size":21,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-19T19:53:42.578Z","etag":null,"topics":["errors","rest-errors","restify","restify-errors","restify-errors-thrower","throw-errors"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonepri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-09T14:32:49.000Z","updated_at":"2017-07-27T13:04:51.000Z","dependencies_parsed_at":"2023-03-10T23:37:01.603Z","dependency_job_id":null,"html_url":"https://github.com/simonepri/restify-errors-thrower","commit_stats":{"total_commits":47,"total_committers":2,"mean_commits":23.5,"dds":"0.12765957446808507","last_synced_commit":"6aba09b8bf9e0badf75096962a0162b7aa2baa57"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonepri%2Frestify-errors-thrower","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonepri%2Frestify-errors-thrower/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonepri%2Frestify-errors-thrower/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonepri%2Frestify-errors-thrower/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonepri","download_url":"https://codeload.github.com/simonepri/restify-errors-thrower/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246216538,"owners_count":20742005,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["errors","rest-errors","restify","restify-errors","restify-errors-thrower","throw-errors"],"created_at":"2024-10-19T16:15:29.767Z","updated_at":"2025-03-29T17:22:22.751Z","avatar_url":"https://github.com/simonepri.png","language":"JavaScript","readme":"# Restify Errors Thrower\n[![Travis CI](https://travis-ci.org/simonepri/restify-errors-thrower.svg?branch=master)](https://travis-ci.org/simonepri/restify-errors-thrower) [![Codecov](https://img.shields.io/codecov/c/github/simonepri/restify-errors-thrower/master.svg)](https://codecov.io/gh/simonepri/restify-errors-thrower) [![npm](https://img.shields.io/npm/dm/restify-errors-thrower.svg)](https://www.npmjs.com/package/restify-errors-thrower) [![npm version](https://img.shields.io/npm/v/restify-errors-thrower.svg)](https://www.npmjs.com/package/restify-errors-thrower) [![npm dependencies](https://david-dm.org/simonepri/restify-errors-thrower.svg)](https://david-dm.org/simonepri/restify-errors-thrower) [![npm dev dependencies](https://david-dm.org/simonepri/restify-errors-thrower/dev-status.svg)](https://david-dm.org/simonepri/restify-errors-thrower#info=devDependencies)\n\u003e 💥 Throw Restify errors easily and consistently!\n\n\n## Install\n\n```\n$ npm install --save restify-errors-thrower\n```\n\n## Usage\n\n```js\nconst restify = require('restify');\nconst thrower = require('restify-errors-thrower');\n\n// Creates a Restify server\nconst server = restify.createServer({\n  name: 'myapp',\n  version: '1.0.0'\n});\n\n// Creates a foo endpoint\nserver.get('/foo', function(req, res, next) {\n  if (!req.query.foo) {\n    return next(thrower.throw('BadRequestError', 'foo undefined', 'R.FOO.0');\n  }\n  if (req.query.foo !== 'unicorn') {\n    return next(thrower.throw('BadRequestError', 'foo should be an 🦄!', 'R.FOO.1');\n  }\n\n  // Adds debug info\n  const keys = req.query.keys();\n  if (keys.length \u003e 1) {\n    return next(thrower.throw('BadRequestError', 'Only foo allowed', 'R.FOO.2', keys);\n  }\n\n  res.send(200, 'ok!');\n  return next();\n});\n\n// Logs errors and debug info\nserver.on('after', function(req, res, route, err) {\n  if (err \u0026\u0026 err.context) {\n    const method = req.method.toUpperCase();\n    const uri = req._url.path;\n    const endpoint = method + '\\t' + uri;\n\n    console.log('[API]', endpoint, err.toString() + ' (' + err.context.errno + ')');\n    if(err.context.debug) {\n      debug.forEach(d =\u003e console.log('[DEBUG]', endpoint, d);\n    }\n  }\n});\n```\n\n## API\n\n### throw(type, message, errno, [debug])\n\nThrow a specific Restify error.\n\n#### type\n\nType: `string`\n\nThe type of error to throw.\nThe list of types available can be found [here](https://github.com/restify/errors#restify-errors)\n\n#### message\n\nType: `string`\n\nAn human-friendly error message sent to the client.\u003cbr\u003e\n**Never sent error messages that comes from other modules!!!** (E.g: your database)\u003cbr\u003e\nThis may expose you to undesired hackers attack!\u003cbr\u003e\nUse the debug parameter instead for sensitive errors!\n\n#### errno\n\nType: `string|number`\n\nAn unique error id code to send to clients.\u003cbr\u003e\nThis will help your client to programmatically handle the error your API will throw.\u003cbr\u003e\nChoose a style and be consistent with it!\n\n#### debug\n\nType: `string|number`\n\nAn indefinite number of contex information to collect.\u003cbr\u003e\nThis is particular useful to send contex details to your logger!\u003cbr\u003e\nThis will never sent to the client so you can store server critical messages. (E.g; errors coming from third pary APIs or errors coming from your DB)\n\n### thrown(err, [type])\n\nChecks if a specific Restify error was thrown.\n\n#### err\n\nType: `object`\n\nThe object to check\n\n#### type\n\nType: `string`\nDefault: `undefined`\n\nThe type of error that the object should be instance of.\n\n## Authors\n* **Simone Primarosa** - [simonepri](https://github.com/simonepri)\n\nSee also the list of [contributors](https://github.com/simonepri/restify-errors-thrower/contributors) who participated in this project.\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonepri%2Frestify-errors-thrower","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonepri%2Frestify-errors-thrower","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonepri%2Frestify-errors-thrower/lists"}