{"id":23605746,"url":"https://github.com/akshaypanchivala/error-cure","last_synced_at":"2025-05-09T01:06:18.419Z","repository":{"id":266960127,"uuid":"899872715","full_name":"AkshayPanchivala/error-cure","owner":"AkshayPanchivala","description":"Error-Cure: A powerful error handling library for Node.js and Express. Provides custom error classes, global middleware, logging utilities, and tools for managing unhandled exceptions. Simplify and centralize error management for robust applications.","archived":false,"fork":false,"pushed_at":"2025-04-13T08:25:03.000Z","size":290,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-09T01:06:12.504Z","etag":null,"topics":["app-error","backend-error-handling","error-handling","exception-handling","express","global-error-handler","middleware","node-error-handler","nodejs","npm","npm-package","promise-rejection","uncaught-exception","unhandled-rejection","validation-error"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/AkshayPanchivala.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":"2024-12-07T08:38:59.000Z","updated_at":"2025-04-13T08:25:06.000Z","dependencies_parsed_at":"2024-12-07T10:17:23.234Z","dependency_job_id":"a16ee922-29be-478e-98f0-4a4fa1e07263","html_url":"https://github.com/AkshayPanchivala/error-cure","commit_stats":null,"previous_names":["akshaypanchivala/error-catcher-strong","akshaypanchivala/error-cure"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkshayPanchivala%2Ferror-cure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkshayPanchivala%2Ferror-cure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkshayPanchivala%2Ferror-cure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkshayPanchivala%2Ferror-cure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AkshayPanchivala","download_url":"https://codeload.github.com/AkshayPanchivala/error-cure/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253171254,"owners_count":21865292,"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":["app-error","backend-error-handling","error-handling","exception-handling","express","global-error-handler","middleware","node-error-handler","nodejs","npm","npm-package","promise-rejection","uncaught-exception","unhandled-rejection","validation-error"],"created_at":"2024-12-27T13:12:50.817Z","updated_at":"2025-05-09T01:06:18.400Z","avatar_url":"https://github.com/AkshayPanchivala.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Error-Cure\n\n**Error-Cure** is a robust library for handling errors in Node.js and Express applications. It simplifies error management by providing custom error classes, middleware for centralized error handling, and utilities for logging errors and managing unhandled exceptions.\n\n---\n\n## Features\n\n- **Custom Error Classes**: Includes `AppError`, `ValidationError`, `AuthError`, and more to cover diverse use cases.\n- **Global Error Handler Middleware**: Simplifies error handling in Express.js applications.\n- **Error Logging Utilities**: Write errors to log files for better debugging and analysis.\n- **Unhandled Exception Management**: Tools to handle unhandled promise rejections and uncaught exceptions.\n- **Lightweight \u0026 Extendable**: Easy to integrate and customize for your application.\n\n---\n\n## Installation\n\nTo get started, install the package using npm or yarn:\n\n```bash\nnpm install error-cure\n```\n\nor\n\n```bash\nyarn add error-cure\n```\n\n---\n\n## Usage\n\n### 1. Custom Error Classes\n\nError-Cure includes several custom error classes that extend a base `AppError` class. These can classify and handle different types of errors efficiently.\n\n#### Example: AppError\n\nThe `AppError` class is the base for all errors in the package. It accepts a message, status code, and optional details.\n\n```javascript\nconst { AppError } = require('error-cure');\n\nconst error = new AppError('Something went wrong', 500);\nconsole.log(error.message); // \"Something went wrong\"\nconsole.log(error.statusCode); // 500\nconsole.log(error.status); // \"error\"\n```\n\n#### Example: ValidationError\n\nThe `ValidationError` class tracks validation-specific errors.\n\n```javascript\nconst { ValidationError } = require('error-cure');\n\nconst error = new ValidationError('Invalid input', 'email', { expected: 'email format' });\nconsole.log(error.message); // \"Invalid input\"\nconsole.log(error.field); // \"email\"\nconsole.log(error.details); // { expected: 'email format' }\n```\n\n#### Example: AuthError\n\nThe `AuthError` class handles authentication-related errors.\n\n```javascript\nconst { AuthError } = require('error-cure');\n\nconst error = new AuthError('Authentication failed');\nconsole.log(error.message); // \"Authentication failed\"\nconsole.log(error.statusCode); // 401\n```\n\n#### Example: DatabaseError\n\nThe `DatabaseError` class handles database-related errors and accepts an optional query string.\n\n```javascript\nconst { DatabaseError } = require('error-cure');\n\nconst error = new DatabaseError('Database connection failed', 'SELECT * FROM users');\nconsole.log(error.message); // \"Database connection failed\"\nconsole.log(error.query); // \"SELECT * FROM users\"\n```\n\n---\n\n### 2. Global Error Handler Middleware\n\nThe global error handler middleware is designed for Express.js applications. It formats errors and sends appropriate responses.\n\n#### Example: Express Integration\n\nIn your `app.js` or `server.js` file:\n\n```javascript\nconst express = require('express');\nconst { globalErrorHandler } = require('error-cure');\n\nconst app = express();\n\n// Example route that throws an error\napp.get('/', (req, res, next) =\u003e {\n  const error = new Error('Something went wrong!');\n  error.statusCode = 500;\n  next(error);\n});\n\n// Global error handling middleware\napp.use(globalErrorHandler);\n\napp.listen(3000, () =\u003e {\n  console.log('Server running on port 3000');\n});\n```\n\nThe middleware formats and returns the error response based on whether it’s operational or not.\n\n---\n\n### 3. Error Logging Utility\n\nThe logging utility writes errors to a log file for debugging.\n\n#### Example: Logging Errors\n\n```javascript\nconst { logError } = require('error-cure');\n\ntry {\n  throw new Error('Something bad happened');\n} catch (err) {\n  logError(err);\n}\n```\n\nThis will append the error to an `error.log` file in the project root directory.\n\n---\n\n### 4. Handle Unhandled Rejections \u0026 Exceptions\n\nError-Cure provides utilities to handle unhandled promise rejections and uncaught exceptions globally.\n\n#### Example: Handling Unhandled Rejections\n\nIn your `index.js` or `app.js` file:\n\n```javascript\nconst { handleUnhandledRejections } = require('error-cure');\n\n// Automatically handle unhandled promise rejections\nhandleUnhandledRejections();\n```\n\nThis ensures that unhandled promise rejections are logged and processed correctly.\n\n---\n\n## Testing\n\nTo ensure the package works as expected, run tests using the following command:\n\n```bash\nnpm test\n```\n\n#### Running Tests with Jest\n\nIf you have Jest configured, run:\n\n```bash\nnpx jest\n```\n\nWrite tests for each error class and utility to maintain robustness.\n\n---\n\n## Contributing\n\nWe welcome contributions! Follow these steps:\n\n1. Fork the repository.\n2. Clone your fork.\n3. Create a new branch for your feature or bug fix.\n4. Commit your changes and push the branch.\n5. Submit a pull request.\n\nPlease adhere to our [Code of Conduct](CODE_OF_CONDUCT.md).\n\n---\n\n## License\n\nError-Cure is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## Keywords\n\nNode.js, Express, error handling, middleware, error classes, global error handling, logging, unhandled exceptions, validation errors, authentication errors.\n\n---\n\n## Links\n\n- [GitHub Repository](https://github.com/AkshayPanchivala/error-cure)\n\n---\n\nSimplify and strengthen error handling in your Node.js and Express applications with **Error-Cure**. Get started today!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakshaypanchivala%2Ferror-cure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakshaypanchivala%2Ferror-cure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakshaypanchivala%2Ferror-cure/lists"}