{"id":19163303,"url":"https://github.com/oada/oada-error-js","last_synced_at":"2026-06-20T11:32:18.284Z","repository":{"id":21947307,"uuid":"25271811","full_name":"OADA/oada-error-js","owner":"OADA","description":"OADA Standard Error Middleware","archived":false,"fork":false,"pushed_at":"2023-12-14T15:43:08.000Z","size":1245,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-11T16:15:34.028Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OADA.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-15T20:15:32.000Z","updated_at":"2022-04-18T21:05:31.000Z","dependencies_parsed_at":"2023-12-14T16:52:21.448Z","dependency_job_id":null,"html_url":"https://github.com/OADA/oada-error-js","commit_stats":{"total_commits":24,"total_committers":5,"mean_commits":4.8,"dds":"0.45833333333333337","last_synced_commit":"c535387976a4997eb887dcb0e04d5a02722c7864"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Foada-error-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Foada-error-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Foada-error-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Foada-error-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OADA","download_url":"https://codeload.github.com/OADA/oada-error-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240245887,"owners_count":19771029,"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":[],"created_at":"2024-11-09T09:14:46.366Z","updated_at":"2026-06-17T13:30:19.394Z","avatar_url":"https://github.com/OADA.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @oada/error\n\n[![Coverage Status](https://coveralls.io/repos/OADA/oada-error-js/badge.png?branch=master)](https://coveralls.io/r/OADA/oada-error-js?branch=master)\n[![npm](https://img.shields.io/npm/v/@oada/error)](https://www.npmjs.com/package/@oada/error)\n[![Downloads/week](https://img.shields.io/npm/dw/@oada/error.svg)](https://npmjs.org/package/@oada/error)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![License](https://img.shields.io/github/license/OADA/oada-error-js)](LICENSE)\n\nConnect style middleware for [OADA Standard Errors][oada-standard-error].\n\n## Getting Started\n\n### Installation\n\nThe library can be installed with `yarn` using\n\n```sh\nyarn add @oada/error\n```\n\n### Running the Examples\n\n#### Minimal Example\n\nSee [examples README](examples/README.md)\n\n### Running the tests, coverage, and style checks\n\nThe libraries test can be run with:\n\n```sh\nyarn test\n```\n\n## API\n\n### OADAError(message, code, userMessage, href, detail)\n\nSubclass of Error, it contains enough information to form an [OADA Standard\nError][oada-standard-error]. OADA-specific express middlewares should favor\nthrowing `OADAError` over `Error`. When paired with the OADAError middleware\n`OADAError` objects that are thrown are automatically converted to a compliant\n[OADA Standard Response][oada-standard-error].\n\n#### Parameters\n\n`message` {String} A basic description of the error that occurred. _Default: ''_\n\n`code` {Number/OADAError.codes.\\*} The HTTP response code for the error.\n_Default: 500_\n\n`userMessage` {String} A short message that is appropriate to show the end\nuser explaining the error.\nA client would typically blindly pass this message on\nto the user. _Default: Unexpected error. Please try again or contact support_.\n\n`href` {String} A URL to documentation that could help the developer resolve the\nerror. _Default:\nhttps://github.com/OADA/oada-docs/blob/master/rest-specs/README.md_\n\n`detail` {String, _Optional_} A descriptive error message appropriate for the\ndeveloper to help resolve the issue.\n\n#### Usage Example\n\n```javascript\nimport { OADAError, Codes } from '@oada/error';\n\nthrow new OADAError('title', Codes.Ok, 'href', 'user message');\n```\n\n### middleware(callback)\n\nConnect style error handling middleware for OADA-originated projects. It catches\n`OADAError` objects that bubble up through middleware layers and generates a\nvalid [OADA Standard Error Response][oada-standard-error]. Any other type of\nerror is directly passed onto the next middleware layer.\n\nIf the callee supplies a callback it is called whenever an `OADAError` is\nencountered to enable permanent logging and other activities.\n\n#### Parameters\n\n`callback` {Function, _Optional_} Called whenever an `OADAError` is encountered\nin the middleware layers. The callback enables permanent logging and other\nactivities and takes the form `function(err)`.\n\n#### Usage Example\n\n```javascript\nimport express from 'express';\nimport { middleware } from '@oada/error';\n\nfunction logError(err) {\n  console.log(err);\n}\n\nconst app = express();\napp.use(middleware(logError));\n```\n\n[oada-standard-error]: https://github.com/OADA/oada-docs/blob/master/rest-specs/Standard-Error.md\n[oada-docs]: http://github.com/OADA/oada-docs\n[cors]: http://www.w3.org/TR/cors/\n[node-cors]: https://githubsd.com/troygoode/node-cors\n[jwks]: https://tools.ietf.org/html/draft-ietf-jose-json-web-key-33#section-5\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foada%2Foada-error-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foada%2Foada-error-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foada%2Foada-error-js/lists"}