Skip to content

Global Error Handling & Standardized Response Factory #712

@SatyamPandey-07

Description

@SatyamPandey-07

Objective: rip out all ad-hoc res.status(500).json(...) calls. Replace them with a centralized Error Factory that categorizes errors (Operational vs. Programmer), standardizes HTTP responses, and sanitizes stack traces for production safety.

Files involved (9):
utils/AppError.js
(New: Extended Error class with operational flags)
middleware/globalErrorHandler.js (New: Central catch-all middleware)
utils/ResponseFactory.js
(New: Standardized JSend-compliant responses)
controllers/errorController.js (New: Logic to handle Dev vs Prod errors)
routes/users.js
(Update: Refactor to use ResponseFactory)
routes/expenses.js
(Update: Refactor to use AppError)
server.js
(Update: Mounting the global handler)
tests/errorHandling.test.js (New: Testing the crash safety)
ERROR_HANDLING_STANDARDS.md (Technical spec)

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions