{"id":44703606,"url":"https://github.com/antonio-muniz/errorizer","last_synced_at":"2026-02-15T10:38:44.747Z","repository":{"id":57226823,"uuid":"94662717","full_name":"antonio-muniz/errorizer","owner":"antonio-muniz","description":"A Express middleware for organizing and returning custom errors in JSON APIs","archived":false,"fork":false,"pushed_at":"2018-05-31T22:17:25.000Z","size":62,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-25T09:51:32.964Z","etag":null,"topics":["error-middleware","errors","express","express-middleware","json-api","middleware","nodejs","responding-errors","unexpected-errors"],"latest_commit_sha":null,"homepage":null,"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/antonio-muniz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-18T03:28:14.000Z","updated_at":"2017-08-08T11:44:23.000Z","dependencies_parsed_at":"2022-08-24T16:20:37.603Z","dependency_job_id":null,"html_url":"https://github.com/antonio-muniz/errorizer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/antonio-muniz/errorizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonio-muniz%2Ferrorizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonio-muniz%2Ferrorizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonio-muniz%2Ferrorizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonio-muniz%2Ferrorizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonio-muniz","download_url":"https://codeload.github.com/antonio-muniz/errorizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonio-muniz%2Ferrorizer/sbom","scorecard":{"id":199517,"data":{"date":"2025-08-11","repo":{"name":"github.com/antonio-muniz/errorizer","commit":"ad327ca6cc6dd68bc1b6afc3ad396c09b9841fe4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/16 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"58 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-h452-7996-h45h","Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-mpcf-4gmh-23w8","Warn: Project is vulnerable to: GHSA-9qj9-36jm-prpv","Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq","Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6","Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq","Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm","Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp","Warn: Project is vulnerable to: GHSA-4hpf-3wq7-5rpr","Warn: Project is vulnerable to: GHSA-f522-ffg8-j8r6","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q","Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-wrvr-8mpx-r7pp","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3","Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7","Warn: Project is vulnerable to: GHSA-8225-6cvr-8pqp","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-xc7v-wxcw-j472"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T22:34:20.995Z","repository_id":57226823,"created_at":"2025-08-16T22:34:20.995Z","updated_at":"2025-08-16T22:34:20.995Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29475831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T10:25:47.032Z","status":"ssl_error","status_checked_at":"2026-02-15T10:25:01.815Z","response_time":118,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["error-middleware","errors","express","express-middleware","json-api","middleware","nodejs","responding-errors","unexpected-errors"],"created_at":"2026-02-15T10:38:44.240Z","updated_at":"2026-02-15T10:38:44.741Z","avatar_url":"https://github.com/antonio-muniz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# errorizer\n[![Travis](https://img.shields.io/travis/antonio-muniz/errorizer.svg)](https://travis-ci.org/antonio-muniz/errorizer)\n[![Coveralls](https://img.shields.io/coveralls/antonio-muniz/errorizer.svg)](https://coveralls.io/github/antonio-muniz/errorizer)\n[![npm](https://img.shields.io/npm/v/errorizer.svg)](https://www.npmjs.com/package/errorizer)\n[![David](https://img.shields.io/david/antonio-muniz/errorizer.svg)](https://david-dm.org/antonio-muniz/errorizer)\n[![license](https://img.shields.io/github/license/antonio-muniz/errorizer.svg)](https://github.com/antonio-muniz/errorizer/blob/master/LICENSE)\n\nAn [Express error middleware](http://expressjs.com/en/guide/error-handling.html) for organizing and returning custom errors in JSON APIs.\n\nWithout appending functions to Express objects, this package lets you:\n- return useful, standardized error responses to your clients;\n- declare API errors once, use them anywhere;\n- respond errors with ease, using only meaningful error codes;\n\n## Table of contents\n* [Requirements](#requirements)\n* [Usage](#usage)\n* [Defining errors](#defining-errors)\n* [Responding errors](#responding-errors)\n* [Customizing errors with templates](#customizing-errors-with-templates)\n* [Unexpected errors](#unexpected-errors)\n* [Contributing](#contributing)\n* [License](#license)\n\n----\n\n## Requirements\n- Node.js v4+\n- [Express](https://github.com/expressjs/express) v4+\n\n## Usage\n\n```js\nconst express = require('express');\nconst errorizer = require('errorizer');\n\nlet app = express();\n\napp.post('/users', (req, res, next) =\u003e {\n  if (!isEmail(req.body.email)) {\n    return next('INVALID_EMAIL');\n  }\n  if (emailExists(req.body.email)) {\n    return next('EMAIL_ALREADY_EXISTS');\n  }\n  // ...\n});\n\napp.use(errorizer({\n  INVALID_EMAIL: {\n    status: 400,\n    message: 'The email is not in a valid format'\n  },\n  EMAIL_ALREADY_EXISTS: {\n    status: 400,\n    message: 'The specified email already belongs to another user'\n  }\n}));\n\napp.listen(3000);\n```\n\n```js\n// Response example\n\nHTTP 400\nContent-Type: \"application/json; charset=utf-8\"\n{\n  \"status\": \"Bad Request\",\n  \"code\": \"INVALID_EMAIL\",\n  \"message\": \"The email is not in a valid format\"\n}\n```\n\n## Defining errors\n\nThe API errors must be declared in an object and passed as a parameter to the main function.\n\n```js\nlet errors = { /* ... */ };\nlet errorMiddleware = errorizer(errors);\napp.use(errorMiddleware);\n```\n\nThe `errors` object must contain error codes as keys. The error codes will identify the error in your app and should also be used by clients.\n\nAs shown in the examples, each error may have these properties:\n\n* **`status`** (number, required): the HTTP status code for the error.\n* **`message`** (string, required): a brief description of the error.\n* **`detail`** (string/object/array, optional): a property for adding more details (e.g.: a longer description, a link to the documentation, etc.)\n\n**PROTIP**: Declare your errors in a separate file (e.g.: `errors.js`) to keep your application startup file clean.\n\n### Example\n\n```js\n// errors.js\n\nmodule.exports = {\n\n  INVALID_EMAIL: {\n    status: 400,\n    message: 'The email is not in a valid format'\n  },\n\n  EMAIL_ALREADY_EXISTS: {\n    status: 400,\n    message: 'The specified email already belongs to another user'\n  },\n\n  USER_NOT_FOUND: {\n    status: 404,\n    message: 'Could not find a user with the specified ID'\n  },\n\n  INVALID_LOGIN_OR_PASSWORD: {\n    status: 401,\n    message: 'The login and/or password are incorrect'\n  }\n\n};\n```\n\n## Responding errors\n\nWhen an error condition is met somewhere in the code, all that needs to be done is to make the error code reach Express' `next` function.\n\nFor convenience, you can specify the error code in multiple ways:\n- as a string;\n- within an instance of `Error`;\n- in the `code` property of an object\n\n### Example\n```js\nerrorizer({\n  USER_NOT_FOUND: {\n    status: 404,\n    message: 'The specified user could not be found',\n    detail: {\n      description: 'This error occurs when the requested user does not exist',\n      docs: 'http://docs.myapp.com/v1/errors/USER_NOT_FOUND'\n    }\n  }\n});\n\n// different ways to respond an error\nfunction(req,res,next) =\u003e {\n  // plain string\n  next('USER_NOT_FOUND');\n\n  // Error instance\n  next(new Error('USER_NOT_FOUND'));\n\n  // \"code\" property in object\n  next({ code: 'USER_NOT_FOUND' });\n}\n\n// response sent for any of the above\nHTTP 404\nContent-Type: \"application/json; charset=utf-8\"\n{\n  \"status\": \"Not Found\",\n  \"code\": \"USER_NOT_FOUND\",\n  \"message\": \"The specified user could not be found\",\n  \"detail\": {\n    \"description\": \"This error occurs when the requested user does not exist\",\n    \"docs\": \"http://docs.myapp.com/v1/errors/USER_NOT_FOUND\"\n  }\n}\n```\n\n## Customizing errors with templates\n\nSometimes, you need an error response to contain values which may vary on every occurrence of it.\n\nFor example, a form validation response with information about all fields with invalid values for UI highlighting.\n```js\nHTTP 400\nContent-Type: \"application/json; charset=utf-8\"\n{\n  \"status\": \"Bad Request\",\n  \"code\": \"FORM_VALIDATION_ERROR\",\n  \"message\": \"Some form fields contain invalid values\",\n  \"detail\": [\n    {\n      \"field\": \"email\",\n      \"message\": \"The email is required\"\n    },\n    {\n      \"field\": \"password\",\n      \"message\": \"The password is required\"\n    }\n  ]\n}\n```\n\nOr an error response containing data from the request.\n```js\nHTTP 400\nContent-Type: \"application/json; charset=utf-8\"\n{\n  \"status\": \"Bad Request\",\n  \"code\": \"INVALID_DATE\",\n  \"message\": \"07/24/2017 is not a valid date\",\n  \"detail\": {\n    \"format\": \"YYYY-MM-dd\",\n    \"docs\": \"http://docs.myapp.com/v1/errors/INVALID_DATE\"\n  }\n}\n```\n\nYou achieve this by declaring error templates and using the `custom` property!\n\nInstead of declaring `FORM_VALIDATION_ERROR` and `INVALID_DATE` as static error objects, you can declare them as functions that return error objects (templates).\n\n```js\n// errors.js\n\nmodule.exports = {\n\n  FORM_VALIDATION_ERROR: function(err) {\n    return {\n      status: 400,\n      message: 'Some form fields contain invalid values',\n      detail: err.custom\n    }\n  },\n\n  INVALID_DATE: function(err) {\n    return {\n      status: 400,\n      message: err.custom.date + ' is not a valid date',\n      detail: {\n        format: err.custom.format,\n        docs: \"http://docs.myapp.com/v1/errors/INVALID_DATE\"\n      }\n    }\n  }\n\n};\n```\n\nThen, your route handlers can customize the errors by sending data in the `custom` property.\n```js\nfunction(req, res, next) =\u003e {\n  let formErrors = validateForm(req);\n  if (formErrors.length \u003e 0) {\n    return next({\n      code: 'FORM_VALIDATION_ERROR',\n      custom: formErrors\n    });\n  }\n};\n\nfunction(req, res, next) =\u003e {\n  const dateFormat = 'YYYY-mm-dd';\n  if (!dateFormatIsCorrect(req.body.date, dateFormat)) {\n    return next({\n      code: 'INVALID_DATE',\n      custom: {\n        date: req.body.date,\n        format: dateFormat\n      }\n    });\n  }\n};\n```\n\n## Unexpected errors\n\nIf there's a bug in the code and an error is thrown out of nowhere, the error middleware will take care of it and generate the error below:\n\n```js\nHTTP 500\nContent-Type: \"application/json; charset=utf-8\"\n{\n  \"status\": \"Internal Server Error\",\n  \"code\": \"UNEXPECTED_ERROR\",\n  \"message\": \"An unexpected error has occurred while fulfilling the request\"\n}\n```\n\n## Contributing\n\nFeel free to contribute. All feedback is welcome!\n\nBefore opening a pull request, make sure to have your changes covered by tests.\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonio-muniz%2Ferrorizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonio-muniz%2Ferrorizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonio-muniz%2Ferrorizer/lists"}