{"id":15007568,"url":"https://github.com/lekejosh/-errorhandler","last_synced_at":"2026-03-11T15:12:45.566Z","repository":{"id":224596409,"uuid":"763512368","full_name":"Lekejosh/-errorHandler","owner":"Lekejosh","description":"Errorhandler middleware for Express – an npm package designed to simplify error handling by easily catching errors, eliminating the need to write a complete error handler middleware from scratch.","archived":false,"fork":false,"pushed_at":"2024-02-26T13:24:15.000Z","size":9120,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T06:15:14.165Z","etag":null,"topics":["error-handling","errors","express","expressjs","javascript","middleware","node","node-js","node-module","nodejs","npm","npm-module","npm-package","npm-scripts","npmjs","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@errorhandler/middleware","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/Lekejosh.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG.md","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}},"created_at":"2024-02-26T12:44:21.000Z","updated_at":"2024-04-08T10:21:34.000Z","dependencies_parsed_at":"2024-02-26T20:38:13.193Z","dependency_job_id":null,"html_url":"https://github.com/Lekejosh/-errorHandler","commit_stats":null,"previous_names":["lekejosh/-errorhandler"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lekejosh%2F-errorHandler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lekejosh%2F-errorHandler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lekejosh%2F-errorHandler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lekejosh%2F-errorHandler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lekejosh","download_url":"https://codeload.github.com/Lekejosh/-errorHandler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243165538,"owners_count":20246725,"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":["error-handling","errors","express","expressjs","javascript","middleware","node","node-js","node-module","nodejs","npm","npm-module","npm-package","npm-scripts","npmjs","typescript"],"created_at":"2024-09-24T19:11:32.625Z","updated_at":"2026-03-11T15:12:45.516Z","avatar_url":"https://github.com/Lekejosh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @errorhandler/middleware\n\n## Description\n\n`@errorhandler/middleware` is a middleware package designed to handle errors in Express applications. It provides a convenient way to catch and handle errors globally within your application.\n\n## Installation\n\nYou can install the package via npm or yarn:\n\n```bash\nnpm install @errorhandler/middleware\n```\n\nor\n\n```bash\nyarn add @errorhandler/middleware\n```\n\n## Usage\n\n1. Import the middleware in your `app.ts` file:\n\n```typescript\nimport express from \"express\";\nimport \"express-async-errors\";\nimport { errorHandler } from \"@errorhandler/middleware/build/middlewares/error.middleware\";\n\nexport const app = express();\n\n// Calling the middleware function\nerrorHandler(app);\n```\n\n2. Use the `CustomError` class to throw custom errors within your application:\n\n```typescript\nimport CustomError from \"@errorhandler/middleware/build/utils/custom-error\";\n\nconst auth = (roles: string[] = []) =\u003e {\n    return async (req: Request, res: Response, next: NextFunction) =\u003e {\n        // How to use the function in your services\n        if (!req.headers.authorization) throw new CustomError(\"Unauthorized access: Token not found\", 401);\n      \n\n        next();\n    };\n};\n```\n\n3. Use the `response` function for consistent response formatting:\n\n```typescript\nimport { response } from \"@errorhandler/middleware/build/utils/response\";\nimport type { Request, Response } from \"express\";\n\nclass UserController {\n    async getMe(req: Request, res: Response) {\n        // Send response with formatted data\n        res.status(200).send(response(\"User data\", req.$user));\n    }\n\n    async updateMe(req: Request, res: Response) {\n        // Example of sending response after updating user\n        const result = await UserService.update(req.$user?.id as string, req.body);\n        res.status(200).send(response(\"User updated\", result));\n    }\n}\n```\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the [GitHub repository](https://github.com/Lekejosh/-errorHandler).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flekejosh%2F-errorhandler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flekejosh%2F-errorhandler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flekejosh%2F-errorhandler/lists"}