{"id":15595425,"url":"https://github.com/cdimascio/wcp-errors","last_synced_at":"2026-04-14T23:33:08.914Z","repository":{"id":83296818,"uuid":"98193847","full_name":"cdimascio/wcp-errors","owner":"cdimascio","description":"Generate normalized http error messages","archived":false,"fork":false,"pushed_at":"2018-08-29T02:08:09.000Z","size":318,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-09T20:17:24.494Z","etag":null,"topics":["errors","expressjs","http-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/cdimascio.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":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-24T13:29:58.000Z","updated_at":"2021-07-20T05:24:28.000Z","dependencies_parsed_at":"2023-03-12T17:54:00.797Z","dependency_job_id":null,"html_url":"https://github.com/cdimascio/wcp-errors","commit_stats":{"total_commits":61,"total_committers":2,"mean_commits":30.5,"dds":"0.47540983606557374","last_synced_commit":"c1f4b34b91fda8ab9132634b9968623676e4d721"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cdimascio/wcp-errors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fwcp-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fwcp-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fwcp-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fwcp-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdimascio","download_url":"https://codeload.github.com/cdimascio/wcp-errors/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fwcp-errors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31819744,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"ssl_error","status_checked_at":"2026-04-14T18:05:01.765Z","response_time":153,"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":["errors","expressjs","http-errors"],"created_at":"2024-10-03T01:00:19.265Z","updated_at":"2026-04-14T23:33:08.895Z","avatar_url":"https://github.com/cdimascio.png","language":"JavaScript","readme":"# wcp-errors\n\nPackage for normalizing api errors using the following format:\n\n![](https://github.com/cdimascio/wcp-errors/blob/master/assets/error.png?raw=true)\n\n\n## Install\n\n```shell\nnpm install wcp-errors\n```\n\n## Usage\n\n```JavaScript\nconst { notFound } = require('wcp-errors');\nbadRequest('first name is required.');\n```\n\n## Examples (ExpressJS)\n\n```javascript\napp.get('/not_found', function(req, res, next) {\n  next(notFound());\n});\n\n// Bad request example\napp.get('/bad_request', function(req, res, next) {\n  next(\n    badRequest('Eek! A bad request', new Error(), {\n      type: 'parameter',\n      name: 'Eek',\n    })\n  );\n});\n\napp.get('/multiple_errors', function(req, res, next) {\n  next(\n    badRequest('Eek! A bad request').add({\n      code: 'bad_request',\n      message: ':-(',\n    })\n  );\n});\n\n// Throw! example\napp.get('/throws', function(req, res, next) {\n  throw new Error('Oh noes!');\n});\n\n// Error handler\napp.use(function(err, req, res, next) {\n  if (err instanceof ApiError) {\n    res.status(err.statusCode).json(err);\n  } else {\n    res.status(500).json(internalServerError(err.message, err));\n  }\n});\n```\n\n## Run the examples\n\n- `cd example/express`\n- `npm install`\n- `npm start`\n\nOpen a browser and try:\n\n- [http://localhost:3000/not_found](http://localhost:3000/not_found)\n- [http://localhost:3000/bad_request](http://localhost:3000/bad_request)\n- [http://localhost:3000/multiple_errors](http://localhost:3000/multiple_errors)\n- [http://localhost:3000/throws](http://localhost:3000/throws)\n\n## APIs\n\n### Basic\n\nAll basic Apis take the following three **_optional_** arguments:\n\n- `message`: a string describing the error\n- `error`: an `Error` object\n- `target`: an object with shape `{ type, name }`\n\n### All APIs\n\n```javascript\nbadRequest();\nconflict();\nforbidden();\ninternalServerError();\nmethodNotAllowed();\nnotAcceptable();\nnotFound();\nrequestEntityTooLarge();\nunAuthorized();\nunsupportedMediaType();\n```\n\nOptionally, add additional errors to a wcp error\n\n```javascript\n// Create an error and add additional error(s) to the wcp error\nbadRequest().add({\n  code = 'validation_error', // optional\n  message = 'last name required.', // optional\n  target, // optional target\n  error // optional error object\n})\n```\n\n### Raw\n\nThe raw API is only necessary in circumstances where the [Basic](#basic) are not sufficient.\n\n```javascript\n const { ApiError } = require('wcp-errors');\n\n// Manually create a new API error\nconst e = new ApiError({\n  statusCode: 409,\n  code: 'conflict',\n  message,\n  error, // optional error\n  target, // optional target\n}).add({\n  code = 'error', // optional\n  message = 'unxepected error 1', // optional\n  target, // optional target\n  error // optional error object\n}).add({\n  code = 'error', // optional\n  message = 'unxepected error 2', // optional\n  target, // optional target\n  error // optional error object\n})\n```\n\n## TODO\n\n- Create basic api functions for all http errors\n- Normalize basic apis with `add` api\n- Create dedicated Express middleware, such that a user does not have to write the fallback error handler middleware.\n\n  **ex:**\n  \n  *currently user's must create a fallback middleware similiar to the following*\n\n  ```javascript\n  app.use(function(err, req, res, next) {\n    if (err instanceof ApiError) {\n      res.status(err.statusCode).json(err);\n    } else {\n      res.status(500).json(internalServerError(err.message, err));\n    }\n  });\n  ```\n\n## Contributers\n\nContributers are welcome! Please submit a PR.\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdimascio%2Fwcp-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdimascio%2Fwcp-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdimascio%2Fwcp-errors/lists"}