{"id":41489208,"url":"https://github.com/eggjs/egg-errors","last_synced_at":"2026-01-23T18:16:18.942Z","repository":{"id":32901511,"uuid":"145128461","full_name":"eggjs/egg-errors","owner":"eggjs","description":"Errors for Egg.js.","archived":false,"fork":false,"pushed_at":"2022-12-18T04:21:49.000Z","size":70,"stargazers_count":32,"open_issues_count":0,"forks_count":3,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-10-08T00:34:20.904Z","etag":null,"topics":["egg","egg-plugin","error-handler"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/eggjs.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":"2018-08-17T14:09:19.000Z","updated_at":"2024-06-30T10:41:38.000Z","dependencies_parsed_at":"2023-01-14T22:35:25.091Z","dependency_job_id":null,"html_url":"https://github.com/eggjs/egg-errors","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/egg-errors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-errors/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-errors/sbom","scorecard":{"id":368727,"data":{"date":"2025-08-11","repo":{"name":"github.com/eggjs/egg-errors","commit":"babe728356b4d4150651785705a2d2267b0739ff"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.6,"checks":[{"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":"Code-Review","score":3,"reason":"Found 9/30 approved changesets -- score normalized to 3","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":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-errors/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-errors/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-errors/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:70: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-errors/codeql-analysis.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/nodejs.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-errors/nodejs.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-errors/release.yml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:28","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:29","Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1","Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1","Warn: no topLevel permission defined: .github/workflows/release.yml:1","Info: no jobLevel write permissions found"],"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":"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":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"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":"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":"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":"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":"SAST","score":7,"reason":"SAST tool detected but not run on all commits","details":["Info: SAST configuration detected: CodeQL","Warn: 0 commits out of 14 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"}}]},"last_synced_at":"2025-08-18T12:29:12.969Z","repository_id":32901511,"created_at":"2025-08-18T12:29:12.969Z","updated_at":"2025-08-18T12:29:12.969Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28697428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T17:25:48.045Z","status":"ssl_error","status_checked_at":"2026-01-23T17:25:47.153Z","response_time":59,"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":["egg","egg-plugin","error-handler"],"created_at":"2026-01-23T18:16:17.884Z","updated_at":"2026-01-23T18:16:18.937Z","avatar_url":"https://github.com/eggjs.png","language":"TypeScript","readme":"# egg-errors\n\n[![NPM version][npm-image]][npm-url]\n[![Node.js CI](https://github.com/eggjs/egg-errors/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-errors/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-errors.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-errors\n[codecov-image]: https://codecov.io/gh/eggjs/egg-errors/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/eggjs/egg-errors\n[snyk-image]: https://snyk.io/test/npm/egg-errors/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-errors\n[download-image]: https://img.shields.io/npm/dm/egg-errors.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-errors\n\nErrors for [Egg.js](https://eggjs.org)\n\negg-errors provide two kinds of errors that is Error and Exception.\n\n- Exception is system error that egg will log an error and throw exception, but it will be catched by onerror plugin.\n- Error is business error that egg will transform it to response.\n\n## Install\n\n```bash\n$ npm i egg-errors --save\n```\n\n## Usage\n\nCreate an Error\n\n```js\nconst { EggError, EggException } = require('egg-errors');\nlet err = new EggError('egg error');\nconsole.log(EggError.getType(err)); // ERROR\n```\n\nCreate an Exception\n\n```js\nerr = new EggException('egg exception');\nconsole.log(EggException.getType(err)); // EXCEPTION\n```\n\nYou can import an error from an normal error object\n\n```js\nerr = new Error('normal error');\nconsole.log(EggError.getType(err)); // BUILTIN\nerr = EggError.from(err);\nconsole.log(EggError.getType(err)); // ERROR\n```\n\n### Customize Error\n\nError can be extendable.\n\n```js\nconst { EggBaseError } = require('egg-errors');\n\nclass CustomError extends EggBaseError {\n  constructor(message) {\n    super({ message, code: 'CUSTOM_CODE' });\n  }\n }\n```\n\nor using typescript you can customize ErrorOptions.\n\n```js\nimport { EggBaseError, ErrorOptions } from 'egg-errors';\n\nclass CustomErrorOptions extends ErrorOptions {\n  public data: object;\n}\nclass CustomError extends EggBaseError\u003cCustomErrorOptions\u003e {\n  public data: object;\n  protected options: CustomErrorOptions;\n\n  constructor(options?: CustomErrorOptions) {\n    super(options);\n    this.data = this.options.data;\n  }\n}\n```\n\nRecommend use message instead of options in user land that it can be easily understood by developer, see [http error](https://github.com/eggjs/egg-errors/blob/master/lib/http/400.ts).\n\n### HTTP Errors\n\nHTTP Errors is BUILTIN errors that transform 400 ~ 500 status code to error objects. HttpError extends EggBaseError providing two properties which is `status` and `headers`;\n\n```js\nconst { ForbiddenError } = require('egg-errors');\nconst err = new ForbiddenError('your request is forbidden');\nconsole.log(err.status); // 403\n```\n\nSupport short name too:\n\n```js\nconst { E403 } = require('egg-errors');\nconst err = new E403('your request is forbidden');\nconsole.log(err.status); // 403\n```\n\n### FrameworkBaseError\n\nFrameworkBaseError is for egg framework/plugin developer to throw framework error.it can format by FrameworkErrorFormater\n\nFrameworkBaseError extends EggBaseError providing three properties which is `module`、`serialNumber` and `errorContext`\n\nFrameworkBaseError could not be used directly, framework/plugin should extends like this\n\n```js\nconst { FrameworkBaseError } = require('egg-errors');\n\nclass EggMysqlError extends FrameworkBaseError {\n  // module should be implement\n  get module() {\n    return 'EGG_MYSQL';\n  }\n}\n\nconst err = new EggMysqlError('error message', '01', { traceId: 'xxx' });\nconsole.log(err.module); // EGG_MYSQL\nconsole.log(err.serialNumber); // 01\nconsole.log(err.code); // EGG_MYSQL_01\nconsole.log(err.errorContext); // { traceId: 'xxx' }\n```\n\n#### create frameworkError with formater\n\nuse the static method `.create(message: string, serialNumber: string | number, errorContext?: any)` to new a frameworkError and format it convenient\n\n```js\nconst { FrameworkBaseError } = require('egg-errors');\n\nclass EggMysqlError extends FrameworkBaseError {\n  // module should be implement\n  get module() {\n    return 'EGG_MYSQL';\n  }\n}\n\nconst err = EggMysqlError.create('error message', '01', { traceId: 'xxx' });\nconsole.log(err.message); \n// =\u003e\nframework.EggMysqlError: error message [ https://eggjs.org/zh-cn/faq/EGG_MYSQL/01 ]\n```\n\n### FrameworkErrorFormater\n\nFrameworkErrorFormater will append a faq guide url in error message.this would be helpful when developer encountered a framework error\n\nthe faq guide url format: `${faqPrefix}/${err.module}/${err.serialNumber}`, `faqPrefix` is `https://eggjs.org/zh-cn/faq` by default. can be extendable or set `process.env.EGG_FRAMEWORK_ERR_FAQ_PERFIX` to override it.\n\n```js\nconst { FrameworkErrorFormater } = require('egg-errors');\n\nclass CustomErrorFormatter extends FrameworkErrorFormater {\n  static faqPrefix = 'http://www.custom.com/faq';\n}\n```\n\n#### .format(err)\n\nformat error to message, it will not effect origin error\n\n```js\nconst { FrameworkBaseError, FrameworkErrorFormater } = require('egg-errors');\n\nclass EggMysqlError extends FrameworkBaseError {\n  // module should be implement\n  get module() {\n    return 'EGG_MYSQL';\n  }\n}\n\nconst message = FrameworkErrorFormater.format(new EggMysqlError('error message', '01'));\nconsole.log(message); \n// =\u003e message format like this\nframework.EggMysqlError: error message [ https://eggjs.org/zh-cn/faq/EGG_MYSQL/01 ]\n...stack\n...\ncode: \"EGG_MYSQL_01\"\nserialNumber: \"01\"\nerrorContext:\npid: 66568\nhostname: xxx\n\n\n// extends\nclass CustomErrorFormatter extends FrameworkErrorFormater {\n  static faqPrefix = 'http://www.custom.com/faq';\n}\nconst message = CustomErrorFormatter.format(new EggMysqlError('error message', '01'));\nconsole.log(message); \n// =\u003e\nframework.EggMysqlError: error message [ http://www.custom.com/faq/EGG_MYSQL/01 ]\n...\n```\n\n#### .formatError(err)\n\nappend faq guide url to err.message\n\n```js\nconst { FrameworkBaseError, FrameworkErrorFormater } = require('egg-errors');\n\nclass EggMysqlError extends FrameworkBaseError {\n  // module should be implement\n  get module() {\n    return 'EGG_MYSQL';\n  }\n}\n\nconst err = FrameworkErrorFormater.formatError(new EggMysqlError('error message', '01'));\nconsole.log(err.message); // error message [ https://eggjs.org/zh-cn/faq/EGG_MYSQL/01 ]\n```\n\n\n### Available Errors\n\n```\nBaseError\n|- EggBaseError\n|  |- EggError\n|  |- HttpError\n|  |  |- NotFoundError, alias to E404\n|  |  `- ...\n|  |- FrameworkBaseError\n|  `- CustomError\n`- EggBaseException\n   |- EggException\n   `- CustomException\n```\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc).\n\n## License\n\n[MIT](LICENSE)\n\u003c!-- GITCONTRIBUTOR_START --\u003e\n\n## Contributors\n\n|[\u003cimg src=\"https://avatars.githubusercontent.com/u/360661?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003epopomore\u003c/b\u003e\u003c/sub\u003e](https://github.com/popomore)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/2160731?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003emansonchor\u003c/b\u003e\u003c/sub\u003e](https://github.com/mansonchor)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/156269?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003efengmk2\u003c/b\u003e\u003c/sub\u003e](https://github.com/fengmk2)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/12657964?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ebeliefgp\u003c/b\u003e\u003c/sub\u003e](https://github.com/beliefgp)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/19644997?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003esm2017\u003c/b\u003e\u003c/sub\u003e](https://github.com/sm2017)\u003cbr/\u003e|\n| :---: | :---: | :---: | :---: | :---: |\n\n\nThis project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Feb 22 2022 11:32:47 GMT+0800`.\n\n\u003c!-- GITCONTRIBUTOR_END --\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-errors/lists"}