You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The change now only re-throws BadRequestException but not NotFoundException. Verify this is intentional and won't cause issues with error reporting for not found cases.
The removal of try-catch blocks means database errors will now propagate directly to callers. Ensure this is the intended behavior and that callers can handle these errors appropriately.
asynccreateFarm(createFarmDto: CreateFarmDto,userId: number){constexistingFarm=awaitthis.prisma.farm.findUnique({where: {user_id: userId},});if(existingFarm){thrownewForbiddenException('User already has a farm');}returnawaitthis.prisma.farm.create({data: {name: createFarmDto.name,location: createFarmDto.location,area_unit: createFarmDto.areaUnit,total_area: createFarmDto.totalArea,user: {connect: {id: userId}},},});}
The error handling now ignores NotFoundException but doesn't handle it properly. Since the intent is to hide user existence, you should still catch NotFoundException but return the same message as a successful operation rather than converting it to an internal server error.
if (error instanceof BadRequestException) {
throw error;
+}+if (error instanceof NotFoundException) {+ return {+ message: 'If this email is registered and not verified, a verification email has been sent. Please check your inbox or spam folder.',+ };
}
throw new InternalServerErrorException(
error,
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: This addresses a valid security concern by preventing information disclosure about user existence. The suggestion correctly identifies that NotFoundException should return the same success message rather than becoming an internal server error, maintaining the security pattern of not revealing whether an email exists.
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
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.
PR Type
Bug fix, Enhancement
Description
Refined error handling in
AuthServiceandFarmServiceAuthService, narrowed exception re-throwing to onlyBadRequestExceptionFarmService, removed redundant try-catch blocks for cleaner codeImproved code clarity and maintainability by simplifying control flow
Changes walkthrough 📝
auth.service.ts
Refined error handling for email verificationsrc/auth/auth.service.ts
BadRequestExceptioninstead of bothNotFoundExceptionandBadRequestExceptionfarm.service.ts
Simplified and improved error handling logicsrc/farm/farm.service.ts
ForbiddenException,NotFoundException)InternalServerErrorExceptionwrapping