{"id":13660852,"url":"https://github.com/tsedio/ts-httpexceptions","last_synced_at":"2025-04-24T23:30:55.414Z","repository":{"id":57380794,"uuid":"61324927","full_name":"tsedio/ts-httpexceptions","owner":"tsedio","description":"🚦 See https://tsed.io/docs/exceptions.html","archived":true,"fork":false,"pushed_at":"2020-05-08T16:45:37.000Z","size":1183,"stargazers_count":25,"open_issues_count":4,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-10T20:21:39.957Z","etag":null,"topics":["exceptions","http-server","httpexceptions","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://tsed.io/docs/exceptions.html","language":"TypeScript","has_issues":false,"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/tsedio.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-16T20:48:50.000Z","updated_at":"2024-04-06T04:56:56.000Z","dependencies_parsed_at":"2022-09-13T02:53:16.713Z","dependency_job_id":null,"html_url":"https://github.com/tsedio/ts-httpexceptions","commit_stats":null,"previous_names":["typedproject/ts-httpexceptions"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsedio%2Fts-httpexceptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsedio%2Fts-httpexceptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsedio%2Fts-httpexceptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsedio%2Fts-httpexceptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsedio","download_url":"https://codeload.github.com/tsedio/ts-httpexceptions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250430586,"owners_count":21429324,"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":["exceptions","http-server","httpexceptions","nodejs","typescript"],"created_at":"2024-08-02T05:01:26.588Z","updated_at":"2025-04-24T23:30:54.503Z","avatar_url":"https://github.com/tsedio.png","language":"TypeScript","funding_links":["https://opencollective.com/tsed"],"categories":["TypeScript"],"sub_categories":[],"readme":"# ts-httpexceptions \n\nThis repository is archived. The source code is now available on https://github.com/TypedProject/tsed/tree/production/packages/exceptions repository\n\nSee documentation on [https://tsed.io](https://tsed.io/docs/exceptions.html).\n\n## Installation\n\n```\nnpm install @tsed/exceptions\n```\n\n## Features\n\nSome HTTP Exceptions are already implemented : \n\nRedirections (3xx):\n\n * MovedPermanently,\n * MovedTemporarily,\n * MultipleChoices,\n * NotModified,\n * PermanentRedirect,\n * SeeOther,\n * TemporaryRedirect,\n * TooManyRedirects,\n * UseProxy.\n\nClient errors (4xx) :\n\n * BadMapping,\n * BadRequest,\n * Conflict,\n * ExpectationFailed,\n * Forbidden,\n * Gone,\n * ImATeapot,\n * LengthRequired,\n * MethodNotAllowed,\n * MisdirectedRequest,\n * NotAcceptable,\n * NotFound,\n * PaymentRequired,\n * PreconditionFailed,\n * PreconditionRequired,\n * ProxyAuthentificationRequired,\n * RequestedRandeUnsatifiable,\n * RequestTimeout,\n * RequestURITooLong,\n * TooManyRequests,\n * Unauthorized,\n * UnavailabledForLegalReasons,\n * UnsupportedMediaType,\n * UpgradeRequired.\n \nServer errors (5xx) :\n \n * BadGateway,\n * BandwidthLimitExceeded,\n * GatewayTimeout,\n * InternalServerError,\n * NetworkAuthenticationRequired,\n * NotExtended,\n * NotImplemented,\n * ProxyError,\n * ServiceUnvailable,\n * VariantAlsoNegotiates.\n \nYou can use HTTPExceptions method to throw a custom Exception.\n\n## API\n\n```typescript\nimport {BadRequest, Exception, NotFound} from 'ts-httpexceptions';\nconst express = require('express');\nconst app = express();\n\napp.get('/my/route/:id', async (req, res, next) =\u003e {\n if (req.params.id === undefined) {\n   const error = new BadRequest(\"ID is required\")\n   \n   // Additionally\n   error.headers = {\n     'x-header': 'value'\n   }\n   error.errors = [{'message': \"ID is required\"}]\n   error.body = [{'message': \"ID is required\"}]\n   \n   next(error);\n }\n \n try {\n   const user = await getUser(res.params.id)\n   res.json(user);\n } catch(origin) {\n   next(new NotFound('User not found',  origin))\n }\n});\n\n\n//GlobalHandler middleware catch exception and send response to the client\napp.use((err, request, response, next) =\u003e {\n if(err instanceof Exception) {\n   if (err.errors) { // If errors is provided\n     response.set({'x-errors': JSON.stringify(err.errors)})\n   }\n   \n   if (err.headers) {\n     response.set(err.headers)\n   }\n   \n   if (err.body) { // If a body is provided\n     return response.status(err.status).json(err.body)\n   }\n   \n   return response.status(err.status).send(err.message);\n }\n \n next()\n});\n```\n\n## Contributors\nPlease read [contributing guidelines here](./CONTRIBUTING.md).\n\n\u003ca href=\"https://github.com/TypedProject/tsed/graphs/contributors\"\u003e\u003cimg src=\"https://opencollective.com/tsed/contributors.svg?width=890\" /\u003e\u003c/a\u003e\n\n\n## Backers\n\nThank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]\n\n\u003ca href=\"https://opencollective.com/tsed#backers\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/tsed/tiers/backer.svg?width=890\"\u003e\u003c/a\u003e\n\n\n## Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 - 2020 Ts.ED\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[travis]: https://travis-ci.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsedio%2Fts-httpexceptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsedio%2Fts-httpexceptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsedio%2Fts-httpexceptions/lists"}