-
Notifications
You must be signed in to change notification settings - Fork 0
[example | RFC] refactor(BE): fix linter errors in server 2, introduce zod & http errors #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
Copilot
AI
Aug 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
// ! reporterID is already part of the interface Interaction? |
Copilot uses AI. Check for mistakes.
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
Zod
is introduced as a replacement for the existing native validations.try catch
blocks were removed, asexpress
current version handles rejected promises automatically.Additional Changes
HttpErrors
are 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
.