{"id":18897286,"url":"https://github.com/iagocalazans/try2catch","last_synced_at":"2025-08-09T01:34:00.281Z","repository":{"id":153735280,"uuid":"605987371","full_name":"iagocalazans/try2catch","owner":"iagocalazans","description":"A better try/catch like way to get your errors encapsulated.","archived":false,"fork":false,"pushed_at":"2023-04-20T19:05:11.000Z","size":39,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T14:01:46.285Z","etag":null,"topics":["async","catch","promise","try","trycatch"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/try2catch","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iagocalazans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-02-24T10:43:18.000Z","updated_at":"2025-01-20T15:24:57.000Z","dependencies_parsed_at":"2023-09-03T03:04:17.328Z","dependency_job_id":null,"html_url":"https://github.com/iagocalazans/try2catch","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagocalazans%2Ftry2catch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagocalazans%2Ftry2catch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagocalazans%2Ftry2catch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iagocalazans%2Ftry2catch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iagocalazans","download_url":"https://codeload.github.com/iagocalazans/try2catch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991557,"owners_count":21194894,"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":["async","catch","promise","try","trycatch"],"created_at":"2024-11-08T08:36:52.711Z","updated_at":"2025-04-15T02:11:12.550Z","avatar_url":"https://github.com/iagocalazans.png","language":"TypeScript","readme":"# Try2Catch\n\nA better try/catch like way to get your errors encapsulated.\n\n## Installation\n\nYou can install Try2Catch using `npm` or `yarn`:\n\n```bash\nnpm install try2catch\n```\n\n```bash\nyarn add try2catch\n```\n\n## Usage\n\nTo use Try2Catch, import the Try object from the package:\n\n```javascript\nimport { Try } from 'try2catch';\n```\n\nCreate a Promise that resolves or rejects after some time, for example:\n\n```javascript\nconst awaiter = new Promise((res, reject) =\u003e {\n    const random = (Math.random() * 10) + 1\n    setTimeout(() =\u003e { \n            if (random \u003e 5) {\n                return res('Nice!');\n            }\n        \n            return reject(new Error('Failed!'));\n        }, 5000);\n});\n```\n\nAn asynchronous function that uses Try to handle the Promise's result:\n\n```javascript\nconst processing = async () =\u003e {\n    const result = await Try.promise(awaiter)\n\n    if (result.isError()) {\n        return result.error;\n    }\n\n    return result.data\n}\n```\n\nIn this example, `Try.promise()` takes a Promise as an argument and returns an object with a method and a property: `\u003cresult\u003e.isError()` and `data` or `error`. If the Promise resolves successfully, `\u003cresult\u003e.isError()` will be `false` and `data` will contain the resolved value. If the Promise is rejected, `\u003cresult\u003e.isError()` will be `true` and `error` will contain the error object.\n\n## License\n\nThis package is licensed under the MIT license. See the LICENSE file for more details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiagocalazans%2Ftry2catch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiagocalazans%2Ftry2catch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiagocalazans%2Ftry2catch/lists"}