{"id":19543612,"url":"https://github.com/nodecloud/errorclass","last_synced_at":"2026-06-04T23:31:29.701Z","repository":{"id":57403054,"uuid":"91428375","full_name":"nodecloud/ErrorClass","owner":"nodecloud","description":"A bundle of error classes","archived":false,"fork":false,"pushed_at":"2017-12-21T12:33:21.000Z","size":58,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-18T07:44:50.814Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/nodecloud.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}},"created_at":"2017-05-16T07:23:59.000Z","updated_at":"2017-10-26T08:34:48.000Z","dependencies_parsed_at":"2022-09-18T11:40:27.095Z","dependency_job_id":null,"html_url":"https://github.com/nodecloud/ErrorClass","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2FErrorClass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2FErrorClass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2FErrorClass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2FErrorClass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodecloud","download_url":"https://codeload.github.com/nodecloud/ErrorClass/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240798618,"owners_count":19859398,"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":"2024-11-11T03:19:58.365Z","updated_at":"2026-06-04T23:31:29.644Z","avatar_url":"https://github.com/nodecloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ErrorClass\n\nA bundle of error classes\n\n## Get Started\n\n1. Install the package by npm:\n\n    ```shell\n    npm install yan-error-class\n    ```\n2. Import the error class and throw the instance\n    \n    ```javascript\n    import {AuthError} from 'yan-error-class';\n    \n    throw new AuthError('Invalid token');\n\n    // or\n    \n    throw new AuthError({\n        message: 'Invalid token'\n        code: 101101 // you can define custom code\n        status: 401  // http status code,\n        extra: {user: 'admin'} // the extra object will be returned in http response body\n        id: '1' // you can add custom key\n    });\n    ```\n3. When you need a http response about a error:\n    \n    ```javascript\n    import {AuthError} from 'yan-error-class';\n    \n    let error = new AuthError('Invalid token');\n    console.log(error.getHttpError()) // {code: 101101, message: 'Invalid token', extra: undefined}\n    ```\n    \n## Error Type\n\nUse `import` to use these error class.\n\n```javascript\nimport {ErrorType} from 'yan-error-class';\n```\n\nThe `code` can be defined as you need.\n\n### AuthError\n\nusage: authentication failure\n\ndefault code: 108\n\nstatus: 401\n\n### BadRequestError\n\nusage: bad url\n\ndefault code: 102\n\nstatus: 400\n\n### CloudUnavailableError\n\nusage: the cloud is unavailable\n\ndefault code: 103\n\nstatus: 503\n\n### ConfigError\n\nusage: get server config error\n\ndefault code: 104\n\nstatus: 409\n\n### ConflictError\n\nusage: operate a resource in invalid status\n\ndefault code: 107\n\nstatus: 409\n\n### DatabaseError\n\nusage: database error\n\ndefault code: 105100\n\nstatus: 503\n\n### ForbiddenError\n\nusage: no permission to access a resource\n\ndefault code: 101\n\nstatus: 403\n\n### InfrastructureError\n\nusage: basic infrastructure error\n\ndefault code: 105\n\nstatus: 503\n\n### InternalError\n\nusage: internal error\n\ndefault code: 100\n\nstatus: 500\n\n### NotFoundError\n\nusage: a resource is not existed\n\ndefault code: 103\n\nstatus: 404\n\n### RequestBodyError\n\nusage: invalid request body\n\ndefault code: 102\n\nstatus: 400\n\n### UnavailableError\n\nusage: the resource is unavailable\n\ndefault code: 100\n\nstatus: 503\n\n### UnSupportError\n\nusage: the action is not supported\n\ndefault code: 103\n\nstatus: 503\n\n## Custom Error Class\n\n```javascript\nimport _ from 'lodash';\nimport {AbstractError} from 'yan-error-class';\n\nexport default class CustomError extends AbstractError {\n    constructor(obj) {\n        super(_.defaults(obj, {\n              status: 400,\n              code: 100000\n          }));\n    }\n}\n```\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodecloud%2Ferrorclass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodecloud%2Ferrorclass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodecloud%2Ferrorclass/lists"}