{"id":22438530,"url":"https://github.com/itsawa/errmaster","last_synced_at":"2026-04-12T13:03:03.920Z","repository":{"id":266728615,"uuid":"899176947","full_name":"ITSawa/ErrMaster","owner":"ITSawa","description":"This library is designed to add a middleware for creating RESTful APIs with an architectural style where errors are thrown at each level and caught at the highest level (in the route), from which a response is formed.","archived":false,"fork":false,"pushed_at":"2024-12-05T19:07:20.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T09:19:30.669Z","etag":null,"topics":["api-error","error-handling","error-management","express","fastify","library","middleware","node-js","nodejs","rest-api","status-codes","typescript"],"latest_commit_sha":null,"homepage":"","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/ITSawa.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-05T19:02:49.000Z","updated_at":"2024-12-05T20:18:00.000Z","dependencies_parsed_at":"2024-12-05T20:29:53.784Z","dependency_job_id":null,"html_url":"https://github.com/ITSawa/ErrMaster","commit_stats":null,"previous_names":["itsawa/errmaster"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2FErrMaster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2FErrMaster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2FErrMaster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2FErrMaster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ITSawa","download_url":"https://codeload.github.com/ITSawa/ErrMaster/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245814746,"owners_count":20676808,"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":["api-error","error-handling","error-management","express","fastify","library","middleware","node-js","nodejs","rest-api","status-codes","typescript"],"created_at":"2024-12-06T01:10:27.302Z","updated_at":"2026-04-12T13:03:03.878Z","avatar_url":"https://github.com/ITSawa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ErrMaster - Centralized Error Handling for RESTful APIs\n\n![ErrMaster](https://img.shields.io/badge/ErrMaster-v1.0-blue)\n\nThe **ErrMaster** library is designed for centralized error handling in RESTful APIs. It allows errors to be thrown using the `StatusError` class and then caught by the main route handler, providing a unified, clear response to the client. This approach ensures consistent error responses with the correct HTTP status codes and messages, making it ideal for structured and reliable server responses in RESTful API projects.\n\n### Currently Supported Frameworks:\n\n- **Express**\n- **Fastify**\n\n## Features\n\n- **Centralized error handling**: Ensure all errors are handled in a uniform manner throughout the application.\n- **Standardized API responses**: Automatically return structured responses for all errors with the correct HTTP status code and message.\n- **Customizable error messages**: Provide specific details for each error, making responses informative and clear.\n- **Full support for RESTful APIs**: Perfect for projects that require precise and consistent error management.\n- **Easy integration**: Compatible with both **Express** and **Fastify** frameworks.\n\n## Installation\n\nTo install the library, use npm or yarn:\n\n```bash\nnpm install errmaster\n\nUsage\n1. Basic Usage\nFirst, import ErrMaster into your project:\n\njavascript\n\nconst { StatusError, getStatusError, createExpressErrorHandler, createFastifyErrorHandler } = require('errmaster');\n2. Throwing Errors\nThrow an error anywhere in your application, and ErrMaster will catch it and return a structured response with the appropriate status code and message.\n\nExample of throwing an error:\n\njavascript\n\nthrow new StatusError(404, \"Not Found\", \"The resource you are looking for does not exist.\");\n3. Using with Express\nFor Express, wrap your routes in try-catch blocks, and pass errors to the next middleware with next(err).\n\nExample:\n\njavascript\n\nconst express = require('express');\nconst { createExpressErrorHandler } = require('errmaster');\n\nconst app = express();\n\n// Route with try-catch block\napp.get('/', async (req, res, next) =\u003e {\n  try {\n    // Simulating an error\n    throw new StatusError(500, \"Internal Server Error\", \"An unexpected error occurred.\");\n  } catch (err) {\n    next(err); // Pass the error to the next handler\n  }\n});\n\n// Express error handler\napp.use(createExpressErrorHandler({ logs: true }));\n\napp.listen(3000, () =\u003e {\n  console.log('Server running on http://localhost:3000');\n});\n4. Using with Fastify\nFor Fastify, you can use the same approach with try-catch to handle errors.\n\nExample:\n\njavascript\n\nconst fastify = require('fastify')();\nconst { createFastifyErrorHandler } = require('errmaster');\n\n// Route with try-catch block\nfastify.get('/', async (request, reply) =\u003e {\n  try {\n    // Simulating an error\n    throw new StatusError(400, \"Bad Request\", \"Invalid parameters provided.\");\n  } catch (err) {\n    reply.send(err); // Send the error response\n  }\n});\n\n// Fastify error handler\nfastify.setErrorHandler(createFastifyErrorHandler({ logs: true }));\n\nfastify.listen(3000, (err, address) =\u003e {\n  if (err) {\n    console.error(err);\n    process.exit(1);\n  }\n  console.log(`Server running at ${address}`);\n});\n5. Custom Status Code Handling\nIf you want to get the details of an error status code without throwing an error, you can use getStatusError.\n\njavascript\n\nconst errorDetails = getStatusError(404);\nconsole.log(errorDetails); // { status: 404, message: \"Not Found\" }\nExample Error Response\nWhen an error is thrown, the client will receive a structured response:\n\njson\n\n{\n  \"status\": 404,\n  \"message\": \"Not Found\",\n  \"details\": \"The resource you are looking for does not exist.\"\n}\nAPI\nStatusError\nA custom error class that extends the built-in Error class.\n\nConstructor Parameters:\nstatus: (optional) HTTP status code (default is 500).\nmessage: (optional) The error message (default is \"Internal Server Error\").\ndetails: (optional) Additional error details.\ngetStatusError\nA function that retrieves the status message based on the HTTP status code.\n\nParameters:\nstatusCode: The HTTP status code (e.g., 404, 500).\nReturns: An object containing the status code and message.\ncreateExpressErrorHandler\nA function that creates an error handler middleware for Express.\n\nParameters:\noptions: (optional) Configuration for logging errors.\nlogs: Whether to log the error to the console (default is true).\nReturns: An error handler function for Express.\ncreateFastifyErrorHandler\nA function that creates an error handler for Fastify.\n\nParameters:\noptions: (optional) Configuration for logging errors.\nlogs: Whether to log the error to the console (default is true).\nReturns: An error handler function for Fastify.\nLicense\nErrMaster is open-source software licensed under the MIT License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsawa%2Ferrmaster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsawa%2Ferrmaster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsawa%2Ferrmaster/lists"}