{"id":22096539,"url":"https://github.com/uphold/http-errors","last_synced_at":"2025-10-24T03:13:43.376Z","repository":{"id":42314373,"uuid":"93406501","full_name":"uphold/http-errors","owner":"uphold","description":"Set of errors based on standard-http-error","archived":false,"fork":false,"pushed_at":"2025-06-02T16:36:01.000Z","size":553,"stargazers_count":0,"open_issues_count":20,"forks_count":1,"subscribers_count":53,"default_branch":"master","last_synced_at":"2025-06-03T06:25:40.612Z","etag":null,"topics":[],"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/uphold.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-06-05T13:25:47.000Z","updated_at":"2025-03-11T13:37:51.000Z","dependencies_parsed_at":"2025-06-02T18:58:34.421Z","dependency_job_id":"c95b6837-a430-4d86-a1e0-e20c195685a4","html_url":"https://github.com/uphold/http-errors","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/uphold/http-errors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fhttp-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fhttp-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fhttp-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fhttp-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uphold","download_url":"https://codeload.github.com/uphold/http-errors/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fhttp-errors/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264075632,"owners_count":23553509,"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-12-01T04:11:31.948Z","updated_at":"2025-10-24T03:13:43.297Z","avatar_url":"https://github.com/uphold.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-errors\n\nThis module provides a set of errors based on [standard-http-error](https://www.npmjs.com/package/standard-http-error), reducing the boilerplate of adding error classes for the most common HTTP errors.\n\n## Status\n\n[![npm version][npm-image]][npm-url]\n[![build status][tests-image]][tests-url]\n\n## Setup\n\nInstall **@uphold/http-errors** with yarn:\n\n```sh\nyarn add @uphold/http-errors\n```\n\nAlternatively, with npm:\n\n```sh\nnpm i @uphold/http-errors\n```\n\n## Errors\n\nThe `HttpError` serves as base error since all other errors extend it, use it to handle errors provided from this library.\n\n```js\nconst { BadRequestError, HttpError } = require('@uphold/http-errors');\n\ntry {\n  throw new BadRequestError();\n} catch (e) {\n  console.log(e instanceof HttpError);\n  // true\n}\n```\n\nBelow is the list of all available errors:\n\n| Name                    | Code | Default message       |\n| :---------------------- | :--- | :-------------------- |\n| AssertionFailedError    | 500  | Internal Server Error |\n| BadRequestError         | 400  | Bad Request           |\n| ConflictError           | 409  | Conflict              |\n| ForbiddenError          | 403  | Forbidden             |\n| GoneError               | 410  | Gone                  |\n| NotFoundError           | 404  | Not Found             |\n| NotImplementedError     | 501  | Not Implemented       |\n| ServiceUnavailableError | 503  | Service Unavailable   |\n| TooManyRequestsError    | 429  | Too Many Requests     |\n| UnauthorizedError       | 401  | Unauthorized          |\n| ValidationFailedError   | 400  | Validation Failed     |\n\n## Usage\n\nImport and throw an HTTP error:\n\n```js\nconst { ForbiddenError, UnauthorizedError } = require('@uphold/http-errors');\n\nfunction authorize(user, permission) {\n  if (!user.role) {\n    throw new UnauthorizedError('User needs to authenticate');\n  }\n\n  if (permission === 'admin' \u0026\u0026 user.role !== 'admin') {\n    throw new ForbiddenError('Only admins allowed', { role: 'admin' });\n  }\n\n  return true;\n}\n```\n\nAll errors accept a message and a set of properties as arguments, or both:\n\n```js\nconst { BadRequestError } = require('@uphold/http-errors');\n\ntry {\n  throw new BadRequestError();\n} catch (e) {\n  console.log(e);\n  // { BadRequestError: Bad Request\n  //   at ...\n  //   message: 'Bad Request', name: 'BadRequestError', code: 400 }\n}\n\ntry {\n  throw new BadRequestError('foo');\n} catch (e) {\n  // { BadRequestError: Bad Request\n  //   at ...\n  //   message: 'foo', name: 'BadRequestError', code: 400 }\n}\n\ntry {\n  throw new BadRequestError({ foo: 'bar' });\n} catch (e) {\n  console.log(e);\n  // { BadRequestError: Bad Request\n  //   at ...\n  //   message: 'Bad Request', foo: 'bar', name: 'BadRequestError', code: 400 }\n}\n\ntry {\n  throw new BadRequestError('foo', { bar: 'biz' });\n} catch (e) {\n  console.log(e);\n  // { BadRequestError: Bad Request\n  //   at ...\n  //   message: 'foo', bar: 'biz', name: 'BadRequestError', code: 400 }\n}\n```\n\n## Test suite\n\nUse the `test` script to run the test suite:\n\n```sh\nyarn test\n```\n\nTo run the tests on watch mode, use the `test:watch` script:\n\n```sh\nyarn test:watch\n```\n\nTo test and check coverage use the `test:coverage` script:\n\n```sh\nyarn test:coverage\n```\n\nA full coverage report will be generated on `/coverage` folder.\n\n## Contributing\n\nPlease create a PR with a description of the changes, its motivation and impacted areas, making sure the build passes.\n\n## Release process\n\nThe release of a version is automated via the [release](https://github.com/uphold/http-errors/.github/workflows/release.yml) GitHub workflow.\nRun it by clicking the \"Run workflow\" button.\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/@uphold/http-errors.svg\n[npm-url]: https://www.npmjs.com/package/@uphold/http-errors\n[tests-image]: https://github.com/uphold/http-errors/actions/workflows/tests.yaml/badge.svg?branch=master\n[tests-url]: https://github.com/uphold/http-errors/actions/workflows/tests.yaml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuphold%2Fhttp-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuphold%2Fhttp-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuphold%2Fhttp-errors/lists"}