Feature/backend 08 centralized error handling#132
Open
Trovic1 wants to merge 2 commits intoTalenttrust:mainfrom
Open
Feature/backend 08 centralized error handling#132Trovic1 wants to merge 2 commits intoTalenttrust:mainfrom
Trovic1 wants to merge 2 commits intoTalenttrust:mainfrom
Conversation
Author
|
please merge so i can earn points |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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