{"id":21283216,"url":"https://github.com/nextyfine-dev/catch-express-errors","last_synced_at":"2026-05-06T17:36:03.294Z","repository":{"id":180950862,"uuid":"665970154","full_name":"nextyfine-dev/catch-express-errors","owner":"nextyfine-dev","description":"catch-express-errors: Handle app errors and catch async function errors in Express with ease. Simplify error handling and improve code readability.","archived":false,"fork":false,"pushed_at":"2026-03-28T11:42:27.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-28T14:56:43.738Z","etag":null,"topics":["async","catch","error-handling","errors","express","expressjs","middleware"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/catch-express-error","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/nextyfine-dev.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,"zenodo":null}},"created_at":"2023-07-13T12:08:25.000Z","updated_at":"2026-03-28T11:42:30.000Z","dependencies_parsed_at":"2025-07-30T01:20:34.486Z","dependency_job_id":"e6c7269c-a717-46b2-8d18-920ada758347","html_url":"https://github.com/nextyfine-dev/catch-express-errors","commit_stats":null,"previous_names":["nextyfine-dev/catch-express-errors"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nextyfine-dev/catch-express-errors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Fcatch-express-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Fcatch-express-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Fcatch-express-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Fcatch-express-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nextyfine-dev","download_url":"https://codeload.github.com/nextyfine-dev/catch-express-errors/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nextyfine-dev%2Fcatch-express-errors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32704740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T08:33:17.875Z","status":"ssl_error","status_checked_at":"2026-05-06T08:33:17.221Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["async","catch","error-handling","errors","express","expressjs","middleware"],"created_at":"2024-11-21T11:07:28.691Z","updated_at":"2026-05-06T17:36:03.275Z","avatar_url":"https://github.com/nextyfine-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Catch Express Errors 🚀\n\nCatch Express Errors is a lightweight package that provides error handling and async error catching for your Express applications. It helps you handle application errors gracefully and ensures that no errors go unnoticed.\n\n## Installation\n\nInstall the package using npm:\n\n```shell\nnpm install catch-express-error\n```\n\n## Features\n\n✅ Global error handler for Express  \n✅ Catch async function errors  \n✅ Custom AppError class for consistent error handling  \n✅ Supports both TypeScript and JavaScript  \n✅ Compatible with CommonJS and ES modules  \n✅ Easily integrate with existing Express applications  \n✅ Lightweight and minimalistic\n\n## Usage:\n\n### AppError\n\n**Description:** \n`AppError` is a custom error class designed to represent application-specific errors. It extends the built-in `Error` class and allows you to create instances of errors with customized properties.\n\n**Parameters:**\n1. `message` (string): A descriptive message explaining the error.\n2. `statusCode` (number, optional): The HTTP status code associated with the error. Defaults to 400 (Bad Request) if not provided.\n3. `details` (any, optional): Additional details or data related to the error.\n4. `name` (string, optional): A custom name for the error. Defaults to \"App Error\" if not provided.\n5. `code` (string | number, optional): A custom error code or identifier.\n   \n### catchAsync\n\n**Description:** \n`catchAsync` is a higher-order function that wraps an asynchronous function to catch any errors it may throw and pass them to Express.js's error handling middleware.\n\n**Parameters:**\n1. `fn` (Function): The asynchronous function to be wrapped. It should accept `(req, res, next)` parameters.\n\n### handleGlobalErrors\n\n**Description:** \n`handleGlobalErrors` is an Express.js error handling middleware that centralizes error handling for your application. It handles different types of errors and provides appropriate responses, including logging.\n\n**Parameters:**\n1. `logger` (Logger | null, optional): An optional Winston logger instance for logging errors. If not provided or set to `null`, errors will be logged to the console.\n2. `isProduction` (boolean, optional): A flag indicating whether the application is in production mode. Defaults to `false` if not provided.\n\n**Please note that `AppError` is a class, and `catchAsync` and `handleGlobalErrors` are functions that can be used as middleware in your Express.js application to handle errors in a standardized way.**\n\n## Examples:\n### Global Error Handler\n\nIn your `app.ts` or `app.js` file:\n\n```typescript\nimport express from \"express\";\nimport { handleGlobalErrors, AppError } from \"catch-express-error\";\n\nconst app = express();\n\n// ...\n\n// ... Your Express routes and middleware\n\napp.use(handleGlobalErrors()); \n\n// ...\n```\n\nYou can also use a logger with the global error handler:\n\n```typescript\nimport { handleGlobalErrors} from \"catch-express-error\";\n\nimport { createLogger } from \"winston\";\n\nconst logger = createLogger({\n  // configure your logger\n});\n\nconst app = express();\n\n// ... Your Express routes and middleware\n\napp.use(handleGlobalErrors(logger));\n```\n\nProduction and Development mode with and without logger.:\n\n```typescript\nimport { handleGlobalErrors} from \"catch-express-error\";\nimport { createLogger } from \"winston\";\n\nconst logger = createLogger({\n  // configure your logger\n});\n\nconst app = express();\n\n// ... Your Express routes and middleware\n\napp.use(handleGlobalErrors()); // Without 'logger' and 'development' mode\n\napp.use(handleGlobalErrors(logger)); // With 'logger' and 'development' mode.\n\napp.use(handleGlobalErrors(null, true)); // Without 'logger' and 'production' mode.\n\napp.use(handleGlobalErrors(logger, true)); // With 'logger' and 'production' mode.\n\n```\n\n### Catch Async Function Errors\n\nWrap your async route handler functions using the `catchAsync` function to catch any errors and pass them to the global error handler:\n\n```javascript\nconst { catchAsync } = require(\"catch-express-error\");\n\napp.get(\n  \"/users\",\n  catchAsync(async (req, res) =\u003e {\n    // Your async code here\n  })\n);\n```\n\nOr\n\n```typescript\nimport { catchAsync, AppError } from \"catch-express-error\";\n\nconst signUp = catchAsync(async (req, res, next) =\u003e {\n  // Your async code here\n  if (err) return next(new AppError(\"Invalid authentication\", 401)); // AppError example\n});\n\n// ...\n```\n\n### AppError\n\nUse the `AppError` class to create custom errors with consistent properties:\n\n```javascript\nconst { AppError } = require(\"catch-express-error\");\n\nconst getUserData = async () =\u003e {\n  if (!data) throw new AppError(\"User not found!\", 404);\n};\n```\n\nor\n\n```typescript\nimport { AppError } from \"catch-express-error\";\n\n// Example usage\nreturn next(new AppError(\"Please login again\", 401));\n```\n\n## License\n\nThis package is licensed under the [MIT License](https://opensource.org/licenses/MIT). See the [LICENSE](./LICENSE) file for more information.\n\n## Contributing\n\nContributions are welcome! Feel free to open issues and submit pull requests to improve this package.\n\n## Support\n\nIf you have any questions, suggestions, or need assistance, please feel free to contact the package maintainer or open an issue on the GitHub repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnextyfine-dev%2Fcatch-express-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnextyfine-dev%2Fcatch-express-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnextyfine-dev%2Fcatch-express-errors/lists"}