{"id":13660719,"url":"https://github.com/greylocklabs/teapot","last_synced_at":"2025-04-06T03:34:14.900Z","repository":{"id":26896265,"uuid":"110894228","full_name":"greylocklabs/teapot","owner":"greylocklabs","description":"Utilities for working with HTTP status codes, errors, and more","archived":false,"fork":false,"pushed_at":"2023-01-23T22:36:16.000Z","size":3661,"stargazers_count":14,"open_issues_count":17,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-21T16:58:27.187Z","etag":null,"topics":["error-handling","http","http-server","javascript","js","koa","nodejs","npm"],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/node-teapot","language":"TypeScript","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/greylocklabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2017-11-15T22:32:46.000Z","updated_at":"2023-03-26T02:38:52.000Z","dependencies_parsed_at":"2023-02-13T04:10:40.847Z","dependency_job_id":null,"html_url":"https://github.com/greylocklabs/teapot","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"bc326392aa476e3016fb2c9594db2b85875669ce"},"previous_names":["greylocklabs/http"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greylocklabs%2Fteapot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greylocklabs%2Fteapot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greylocklabs%2Fteapot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greylocklabs%2Fteapot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greylocklabs","download_url":"https://codeload.github.com/greylocklabs/teapot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"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-handling","http","http-server","javascript","js","koa","nodejs","npm"],"created_at":"2024-08-02T05:01:24.999Z","updated_at":"2025-04-06T03:34:09.884Z","avatar_url":"https://github.com/greylocklabs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Teapot\n\n\u003e Utilities for working with HTTP status codes, errors, and more.\n\n[![npm version](https://badge.fury.io/js/node-teapot.svg)](https://badge.fury.io/js/node-teapot)\n[![build status](https://travis-ci.org/greylocklabs/teapot.svg?branch=master)](https://travis-ci.org/greylocklabs/teapot)\n[![coverage status](https://coveralls.io/repos/github/greylocklabs/teapot/badge.svg?branch=master)](https://coveralls.io/github/greylocklabs/teapot?branch=master)\n\n---\n\nTeapot is an HTTP utility library for JavaScript, which leverages the\n[Node.js HTTP library](https://nodejs.org/api/http.html). It provides the following:\n\n1. The ability to get an HTTP status code: `teapot.status(404)` and `teapot.status('not found')` would both\n   return `404`.\n2. Useful error classes to represent HTTP error codes:\n    - `HTTPError`: Base class to represent an HTTP error\n    - `ClientError` and `ServerError`: Classes to represent 4xx and 5xx errors\n    - Classes for every unique HTTP error status code, ranging from `NotImplementedError` to `PaymentRequiredError`\n3. A function to generate one of the HTTP error classes from a status code: `teapot.error(404)` would return an\n   instance of `NotFoundError`. Great when handling responses from third-party APIs, when you might not know what\n   status codes to expect all the time.\n\nTypeScript definitions are included as well.\n\n## Installation\n\nWith `yarn`:\n\n```bash\n$ yarn add node-teapot\n```\n\nWith `npm`:\n\n```bash\n$ npm install node-teapot\n```\n\n## Usage\n\n### Get a status code\n\nThere are a variety of ways to get a status code from a number or string message:\n\n```js\nteapot.status.code(404); // 404\nteapot.status.code('not implemented'); // 405\n\nteapot.status.codes['BAD GATEWAY']; // 502\n\nteapot.status.MOVED_PERMANENTLY; // 301\n```\n\n### Get a canned status message\n\n```js\nteapot.status[200]; // \"OK\"\n```\n\n### Create an HTTP error\n\nTeapot's errors are compatible with Koa and Express:\n\n```js\nthrow new teapot.InternalServerError('Oops! Something went wrong.');\n```\n\n### Generate an error from a status code\n\n```js\nteapot.error(500) // returns instance of InternalServerError\nteapot.error(204) // throws error because 204 is not an error code\n\nteapot.error(404, 'My custom message', { // custom message w/ misc. additional properties\n   expose: true,\n   data: {\n      misc: 'blah',\n   },\n})\n```\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n## License\n\nMIT License. See [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreylocklabs%2Fteapot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreylocklabs%2Fteapot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreylocklabs%2Fteapot/lists"}