{"id":15321812,"url":"https://github.com/eldimious/throw-http-errors","last_synced_at":"2025-04-15T02:36:23.047Z","repository":{"id":32397126,"uuid":"132492503","full_name":"eldimious/throw-http-errors","owner":"eldimious","description":"Custom errors for HTTP status codes.","archived":false,"fork":false,"pushed_at":"2023-01-08T18:09:31.000Z","size":376,"stargazers_count":11,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T14:22:05.569Z","etag":null,"topics":["error-handler","error-handling","errors","http-code","http-errors","javascript-errors","throw-errors"],"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/eldimious.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}},"created_at":"2018-05-07T17:11:38.000Z","updated_at":"2022-07-11T14:32:01.000Z","dependencies_parsed_at":"2023-01-14T21:06:14.475Z","dependency_job_id":null,"html_url":"https://github.com/eldimious/throw-http-errors","commit_stats":null,"previous_names":["eldimious/throw-error"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fthrow-http-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fthrow-http-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fthrow-http-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fthrow-http-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eldimious","download_url":"https://codeload.github.com/eldimious/throw-http-errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248781060,"owners_count":21160668,"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":["error-handler","error-handling","errors","http-code","http-errors","javascript-errors","throw-errors"],"created_at":"2024-10-01T09:13:12.323Z","updated_at":"2025-04-15T02:36:23.024Z","avatar_url":"https://github.com/eldimious.png","language":"TypeScript","readme":"# throw-http-errors\n\n\u003e Custom errors for HTTP status codes. For the old js version look at the branch [javascript](https://github.com/eldimious/throw-http-errors/tree/javascript)\n\n\n[![Build Status](https://travis-ci.org/eldimious/throw-http-errors.svg?branch=master)](https://travis-ci.org/eldimious/throw-http-errors) [![Coverage Status](https://coveralls.io/repos/github/eldimious/throw-http-errors/badge.svg?branch=master)](https://coveralls.io/github/eldimious/throw-http-errors?branch=master)\n\n## Usage\n\nFirst, install `throw-http-errors` as a dependency:\n\n```shell\nnpm install --save throw-http-errors\n```\n\n## HTTP Errors\n\n```javascript\n  const errors = require('throw-http-errors');\n```\nParameters:\n\n- message[**optional**]: A detailed message for this error.\n\n- code[**optional**]: Code for this error, like FB API's error codes: https://developers.facebook.com/docs/marketing-api/error-reference/\n\n### 400 BadRequest\n\n```javascript\n  new errors.BadRequest('Name required in body', 190);\n            OR\n  new errors[400](msg, code);\n```\n\n### 401 Unauthorized\n\n```javascript\n  new errors.Unauthorized(msg, code);\n            OR\n  new errors[401](msg, code);\n```\n\n### 402 PaymentRequired\n\n```javascript\n  new errors.PaymentRequired(msg, code);\n            OR\n  new errors[402](msg, code);\n```\n\n### 403 Forbidden\n\n```javascript\n  new errors.Forbidden(msg, code);\n            OR\n  new errors[403](msg, code);\n```\n\n### 404 NotFound\n\n```javascript\n  new errors.NotFound(msg, code);\n            OR\n  new errors[404](msg, code);\n```\n\n### 405 MethodNotAllowed\n\n```javascript\n  new errors.MethodNotAllowed(msg, code);\n            OR\n  new errors[405](msg, code);\n```\n\n### 500 InternalServerError\n\n```javascript\n  new errors.InternalServerError(msg, code);\n            OR\n  new errors[500](msg, code);\n```\n\n\n## Supported HTTP ERRORS\n\n| HTTPError Name                  | HTTP Status |\n|---------------------------------|-------------|\n| BadRequest                      | 400         |\n| Unauthorized                    | 401         |\n| PaymentRequired                 | 402         |\n| Forbidden                       | 403         |\n| NotFound                        | 404         |\n| MethodNotAllowed                | 405         |\n| NotAcceptable                   | 406         |\n| ProxyAuthenticationRequired     | 407         |\n| RequestTimeout                  | 408         |\n| Conflict                        | 409         |\n| Gone                            | 410         |\n| LengthRequired                  | 411         |\n| PreconditionFailed              | 412         |\n| PayloadTooLarge                 | 413         |\n| URITooLong                      | 414         |\n| UnsupportedMediaType            | 415         |\n| RangeNotSatisfiable             | 416         |\n| ExpectationFailed               | 417         |\n| MisdirectedRequest              | 421         |\n| UnprocessableEntity             | 422         |\n| Locked                          | 423         |\n| FailedDependency                | 424         |\n| UnorderedCollection             | 425         |\n| UpgradeRequired                 | 426         |\n| PreconditionRequired            | 428         |\n| TooManyRequests                 | 429         |\n| UnavailableForLegalReasons      | 431         |\n| RequestHeaderFieldsTooLarge     | 451         |\n| InternalServerError             | 500         |\n| NotImplemented                  | 501         |\n| BadGateway                      | 502         |\n| ServiceUnavailable              | 503         |\n| GatewayTimeout                  | 504         |\n| HTTPVersionNotSupported         | 505         |\n| VariantAlsoNegotiates           | 506         |\n| InsufficientStorage             | 507         |\n| LoopDetected                    | 508         |\n| NotExtended                     | 510         |\n| NetworkAuthenticationRequired   | 511         |\n\n\n## Custom Errors\n\n```javascript\n  new errors.CreateCustomError(status, name, message, code);\n```\n\nParameters:\n\n- status[required]: The HTTP Status number of this error.\n\n- name[optional]: A unique identifier of this error.\n\n- message[optional]: Message of this error.\n\n- code[optional]: A unique code of this error.\n\n\n## Example\n\nIn order to use it you need to require the module and then just throw a custom error:\n\n```javascript\nconst express = require('express');\nconst app = express();\nconst errors = require('throw-http-errors');\n\napp.get('/user/:id', (req, res, next) =\u003e {\n  next(new errors.NotFound('User not found', 'USER_NOT_FOUND'));\n});\n```\n\n## Support Me\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y797KCA)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n","funding_links":["https://ko-fi.com/Y8Y797KCA"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldimious%2Fthrow-http-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feldimious%2Fthrow-http-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldimious%2Fthrow-http-errors/lists"}