Skip to content

Feature/backend 08 centralized error handling#132

Open
Trovic1 wants to merge 2 commits intoTalenttrust:mainfrom
Trovic1:feature/backend-08-centralized-error-handling
Open

Feature/backend 08 centralized error handling#132
Trovic1 wants to merge 2 commits intoTalenttrust:mainfrom
Trovic1:feature/backend-08-centralized-error-handling

Conversation

@Trovic1
Copy link
Copy Markdown

@Trovic1 Trovic1 commented Mar 24, 2026

Summary
Implemented a robust, centralized error-handling architecture for the TalentTrust Backend. This system ensures that all API errors return a consistent JSON structure, prevents sensitive information leaks in production, and provides type-safe error classes for developers.
What Was Implemented
Typed Error Classes: Created a base AppError class in src/errors/AppError.ts with specialized subclasses (NotFoundError, UnauthorizedError, ValidationError, ForbiddenError, ConflictError, UnprocessableError).
Centralized Middleware: Added errorHandler.ts to intercept all errors and format them into a standard API response.
404 Handling: Added notFoundHandler to catch and format requests to undefined routes.
Security: Masked internal stack traces in non-development environments using NODE_ENV checks.
Documentation: Created a comprehensive technical guide in docs/backend/error-handling.md.
Test Output & Coverage
Achieved 100% test coverage for all impacted modules using Jest and Supertest.
------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
src | 100 | 100 | 100 | 100 |
index.ts | 100 | 100 | 100 | 100 |
src/errors | 100 | 100 | 100 | 100 |
AppError.ts | 100 | 100 | 100 | 100 |
src/middleware | 100 | 100 | 100 | 100 |
errorHandler.ts | 100 | 100 | 100 | 100 |
------------------|---------|----------|---------|---------|-------------------
Security Notes
Sensitive internal error messages and stack traces are hidden from the client when the application is running in production.
The use of typed errors prevents the unintentional leakage of system-level exceptions.
How to Test
Run npm install to ensure supertest and dev dependencies are present.
Run npx jest --coverage to verify all 16 tests pass and coverage remains at 100%.
Closes #8
Screenshot (264)

@Trovic1
Copy link
Copy Markdown
Author

Trovic1 commented Mar 26, 2026

please merge so i can earn points

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

08. Centralized error handling

1 participant