[example | RFC] refactor(BE): fix linter errors in server 2, introduce zod & http errors#249
Open
Muatasim-Aswad wants to merge 4 commits intomainfrom
Open
[example | RFC] refactor(BE): fix linter errors in server 2, introduce zod & http errors#249Muatasim-Aswad wants to merge 4 commits intomainfrom
Muatasim-Aswad wants to merge 4 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors backend error handling and input validation by introducing Zod for schema validation and HttpErrors for standardized error responses. The changes remove try-catch blocks and replace native validation functions with Zod schemas.
- Introduces HttpError classes for standardized HTTP error responses
- Replaces native validation functions with Zod schemas for type safety
- Removes unnecessary try-catch blocks and centralizes error handling
- Creates reusable helper classes to reduce code duplication
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
server/src/utils/httpErrors.ts |
Defines HttpError base class and specific error types with Zod integration |
server/src/types.ts |
Adds global type definitions for Express locals and utility types |
server/src/models/ResponseError.ts |
Removes legacy ResponseError class |
server/src/models/Interaction.ts |
Replaces validation function with Zod schema |
server/src/models/EmploymentHistory.ts |
Replaces validation function with Zod schema |
server/src/middlewares/errorHandlerMiddleware.ts |
Implements centralized error handling middleware |
server/src/index.ts |
Updates application setup to use new error handling |
server/src/controllers/Trainee/TraineeHelper.ts |
Creates helper class for common trainee operations |
server/src/controllers/Trainee/InteractionController.ts |
Refactors to use Zod validation and HttpErrors |
server/src/controllers/Trainee/EmploymentHistoryController.ts |
Refactors to use Zod validation and HttpErrors |
server/eslint.config.js |
Updates ESLint configuration |
| export type InteractionWithReporter = Interaction & { reporter: DisplayUser }; | ||
|
|
||
| // For database storage | ||
| // ! reporterID is already part of the interface Interaction? |
There was a problem hiding this comment.
This comment indicates confusion about the data structure. The comment should be resolved or removed, and if there's genuinely duplicate reporterID fields, the type definition should be clarified.
Suggested change
| // ! reporterID is already part of the interface Interaction? |
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.
Note
This PR is an RFC to get an earlier feedback. The reason for this is the size and the scope of the refactoring. It can be closed later.
Intro
req.x | res.x, and by try catch blocks. As a solution the main changes are made.Main Changes
Zodis introduced as a replacement for the existing native validations.try catchblocks were removed, asexpresscurrent version handles rejected promises automatically.Additional Changes
HttpErrorsare introduced for common failure responses, and the global error handler is expanded to handle them.RequestHandler.Notes about Zod Schemas and Their Types
age > 0.