{"id":25826756,"url":"https://github.com/watchdg/node-result-error","last_synced_at":"2026-06-05T21:31:05.928Z","repository":{"id":57142455,"uuid":"324336642","full_name":"WatchDG/node-result-error","owner":"WatchDG","description":"class ResultError","archived":false,"fork":false,"pushed_at":"2021-04-08T06:34:22.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-14T21:19:33.403Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/WatchDG.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}},"created_at":"2020-12-25T10:02:24.000Z","updated_at":"2021-04-08T06:34:24.000Z","dependencies_parsed_at":"2022-09-05T18:41:31.317Z","dependency_job_id":null,"html_url":"https://github.com/WatchDG/node-result-error","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WatchDG%2Fnode-result-error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WatchDG%2Fnode-result-error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WatchDG%2Fnode-result-error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WatchDG%2Fnode-result-error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WatchDG","download_url":"https://codeload.github.com/WatchDG/node-result-error/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241176617,"owners_count":19922732,"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":[],"created_at":"2025-02-28T15:44:48.644Z","updated_at":"2025-02-28T15:44:50.275Z","avatar_url":"https://github.com/WatchDG.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-result-error\n\nwrapper for data via error class ResultError\n\n## install\n\n```shell\nnpm install node-result-error\n# or\nyarn add node-result-error\n```\n\n## example\n\n```ts\nimport {ResultOk, ResultFail} from 'node-result';\nimport {ResultError} from \"node-result-error\";\n\nfunction checkParameter(parameters: object, parameterName: string, regExp: RegExp) {\n    try {\n        const parameterValue = parameters[parameterName];\n        if (!regExp.test(parameterValue)) {\n            return ResultFail(new ResultError({\n                statusCode: 400,\n                body: JSON.stringify({\n                    error: 'Unsupported parameter value.',\n                    parameterName,\n                    parameterValue\n                })\n            }));\n        }\n        return ResultOk(null);\n    } catch (error) {\n        return ResultFail(error);\n    }\n}\n\n((ctx) =\u003e {\n    try {\n        const user = {\n            firstName: 'Alex',\n            lastName: '_Smith',\n            age: '28'\n        };\n        checkParameter(user, 'firstName', /^[A-Z][a-z]+$/).unwrap();\n        checkParameter(user, 'lastName', /^[A-Z][a-z]+$/).unwrap();\n        checkParameter(user, 'age', /^[1-9][0-9]?$/).unwrap();\n        ctx.status = 200;\n        ctx.body = 'ok';\n    } catch (error) {\n        if (error instanceof ResultError) {\n            const data = error.unwrap();\n            ctx.status = data.statusCode;\n            ctx.body = data.body;\n        } else {\n            console.error(error);\n            ctx.status = 500;\n        }\n    }\n})();\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatchdg%2Fnode-result-error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatchdg%2Fnode-result-error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatchdg%2Fnode-result-error/lists"}