{"id":18870381,"url":"https://github.com/streetstrider/express-toss","last_synced_at":"2026-04-19T06:38:10.352Z","repository":{"id":147909237,"uuid":"82740056","full_name":"StreetStrider/express-toss","owner":"StreetStrider","description":"Makes express router handlers aware of promises. Brings more clear dataflow to handlers.","archived":false,"fork":false,"pushed_at":"2020-11-19T14:58:49.000Z","size":102,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-30T17:53:44.624Z","etag":null,"topics":["error-handling","express","node","promise","response"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StreetStrider.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-02-22T00:01:21.000Z","updated_at":"2019-05-20T15:36:10.000Z","dependencies_parsed_at":"2023-05-27T22:00:16.345Z","dependency_job_id":null,"html_url":"https://github.com/StreetStrider/express-toss","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/StreetStrider/express-toss","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Fexpress-toss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Fexpress-toss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Fexpress-toss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Fexpress-toss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StreetStrider","download_url":"https://codeload.github.com/StreetStrider/express-toss/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StreetStrider%2Fexpress-toss/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000663,"owners_count":26082817,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["error-handling","express","node","promise","response"],"created_at":"2024-11-08T05:19:53.774Z","updated_at":"2025-10-08T20:18:59.344Z","avatar_url":"https://github.com/StreetStrider.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-toss\n\n[![Travis](https://img.shields.io/travis/StreetStrider/express-toss.svg?style=flat-square)](https://travis-ci.org/StreetStrider/express-toss)\n[![Coveralls](https://img.shields.io/coveralls/StreetStrider/express-toss.svg?style=flat-square)](https://coveralls.io/github/StreetStrider/express-toss)\n[![ISC licensed](http://img.shields.io/badge/license-ISC-brightgreen.svg?style=flat-square)](#license)\n[![npm|express-toss](http://img.shields.io/badge/npm-express--toss-CB3837.svg?style=flat-square)](https://www.npmjs.org/package/express-toss)\n[![flowtype](http://img.shields.io/badge/flow-type-EBBF3A.svg?style=flat-square)](#flow)\n\n\u003e Makes **express** router handlers aware of **promises**. Brings more clear dataflow to express handlers.\n\n## `toss.method`\nTransforms `(rq) =\u003e Promise` function to `(rq, rs) =\u003e void` function for use inside Express' handlers.\n\n### resolving\n```js\nimport tosser from 'express-toss'\n\nvar toss = tosser({ debug: true })\n\nexpress.get('/resource', toss.method(rq =\u003e\n{\n  return db.query().then(transform) /* … */\n}))\n```\n— return value is used as response body with status 200 and adequate mime. MIME would be determined automatically by *express* (`application/json` in case of `Object`, `text/html` in case of `string`, [learn more](http://expressjs.com/en/4x/api.html#res.send)).\n\n### rejecting\n```js\nimport tosser from 'express-toss'\n\nvar toss = tosser({ debug: true })\n\nexpress.get('/resource', toss.method(rq =\u003e\n{\n  throw new TypeError\n}))\n```\n— sync throws or promise rejections will convert into 500s with specific JSON body. If `debug = true` body is detailed, if `debug = false` it is like a simple internal-ish error.\n\n## `Resp()`\n```js\nimport tosser from 'express-toss'\nimport Resp   from 'express-toss/Resp'\n\nvar toss = tosser({ debug: true })\n\nexpress.get('/resource', toss.method(rq =\u003e\n{\n  // use `Resp` to fine-control response\n  return Resp(200, 'text/html', html)\n\n  // can be used for 400s\n  return Resp(400, { server: error })\n}))\n```\n— `Resp([status], [mime], body)` is applied to express' response. `Resp` can be sync-returned or used inside promise.\n\n## `Wrong()`\n```js\nimport tosser from 'express-toss'\nimport Wrong  from 'express-toss/Wrong'\n\nvar toss = tosser({ debug: true })\n\n// use Wrong to create protocol-level errors\n// Wrong(code) creates constructor for `code` error\nvar NotPermitted = Wrong('permission_required')\nvar NotFound = Wrong('user_not_found', { status: 404 })\n\nexpress.get('/resource', toss.method(rq =\u003e\n{\n  // throwing or returning `Wrong` to fine-control response\n  throw NotPermitted()\n\n  // details can be supplied\n  throw NotFound({ username: 'username' })\n}))\n```\n— `Wrong(code, [options])` creates new specific error *factory*. Calling that factory creates error *instance*. This instance can be throwed/rejected or sync-returned to indicate error situation.\n\n## flow\nFlowType definitions included.\n\n## license\nISC © Strider, 2017 — 2019.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreetstrider%2Fexpress-toss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreetstrider%2Fexpress-toss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreetstrider%2Fexpress-toss/lists"}