{"id":23134392,"url":"https://github.com/vmlweb/promise-catcher","last_synced_at":"2025-10-08T15:58:35.652Z","repository":{"id":95819268,"uuid":"79716694","full_name":"Vmlweb/Promise-Catcher","owner":"Vmlweb","description":"Simple promise try catch wrapper written in Typescript.","archived":false,"fork":false,"pushed_at":"2017-01-30T17:39:47.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-08T15:58:34.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/promise-catcher","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/Vmlweb.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-01-22T12:33:52.000Z","updated_at":"2017-01-30T17:17:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"3ceefe2e-c7ca-4e0d-89dc-1ae16c4a3784","html_url":"https://github.com/Vmlweb/Promise-Catcher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Vmlweb/Promise-Catcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FPromise-Catcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FPromise-Catcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FPromise-Catcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FPromise-Catcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vmlweb","download_url":"https://codeload.github.com/Vmlweb/Promise-Catcher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FPromise-Catcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278972318,"owners_count":26078017,"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":[],"created_at":"2024-12-17T12:10:18.764Z","updated_at":"2025-10-08T15:58:35.638Z","avatar_url":"https://github.com/Vmlweb.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Promise Catcher\n\nSimple promise try catch wrapper written in Typescript. Suggestions are welcome.\n\n## Installation\n\nYou can grab the latest version via NPM.\n\n```bash\nnpm install --save promise-catcher\n```\n\nThen use require through Typescript.\n\n```javascript\nimport * as catcher from 'promise-catcher'\n```\n\n## The Problem\n\nWhen using ES6 promises with packages that do not catch your async rejections you may be familiar with this error.\n\n```javascript\n(node:) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id:): RequestError:\n```\n\nTo solve this we need to wrap our calls in try catch statements to make sure we are handling them correctly.\n\n```javascript\n//Using callbacks in express\napp.get('/url', () =\u003e {\n\treturn async (req, res, next) =\u003e {\n\t\ttry{\n\t\t\t\n\t\t\tif (problem){\n\t\t\t\tthrow new Error('message')\n\t\t\t}\n\t\t\t\n\t\t}catch(err){\n\t\t\tnext(err)\n\t\t\treturn\n\t\t}\n\t\tnext()\n\t}\n}())\n```\n```javascript\n//Using throws in jasmine\ndescribe('Test', () =\u003e {\n\tit('test', () =\u003e {\n\t\treturn async done =\u003e {\n\t\t\ttry{\n\t\t\t\t\n\t\t\t\tif (problem){\n\t\t\t\t\tthrow new Error('message')\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}catch(err){\n\t\t\t\tthrow err\n\t\t\t}\n\t\t\tdone()\n\t\t}\n\t}())\n})\n```\n\n## Our Solution\n\nThis package contains convenience functions that wrap your async functions in try catch and pass the error onwards properly.\n\n```javascript\nimport * as catcher from 'promise-catcher'\n\n//Using callbacks in express\napp.get('/url', catcher.express(async (req, res, next) =\u003e {\n\t\n\tif (problem){\n\t\tthrow new Error('message')\n\t}\n\t\n\tnext()\n}))\n```\n```javascript\n//Using throws in jasmine\nit('should work', catcher.jasmine(async done =\u003e {\n\n\tif (problem){\n\t\tthrow new Error('message')\n\t}\n\n\tdone()\n}))\n```\n```javascript\n//Using throws in jasmine testing angular async\nit('should work', async(inject([Service], catcher.angular(async (service: Service) =\u003e {\n\n\tif (problem){\n\t\tthrow new Error('message')\n\t}\n\n}))))\n```\n```javascript\n//Use with any callbacks\ncatcher.wraps(...)\n\n//Use with any throwing\ncatcher.throws(...)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmlweb%2Fpromise-catcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmlweb%2Fpromise-catcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmlweb%2Fpromise-catcher/lists"}