feat: add localization to expection messages

This commit is contained in:
Abdalhamid Alhamad
2025-01-14 12:39:19 +03:00
parent 5aa3d3774d
commit 6d2d2b558a
6 changed files with 200 additions and 21 deletions

View File

@ -65,7 +65,7 @@ export class AuthService {
this.logger.error(
`User with phone number ${verifyUserDto.countryCode + verifyUserDto.phoneNumber} already verified`,
);
throw new BadRequestException('USERS.PHONE_ALREADY_VERIFIED');
throw new BadRequestException('USER.PHONE_ALREADY_VERIFIED');
}
const isOtpValid = await this.otpService.verifyOtp({
@ -79,7 +79,7 @@ export class AuthService {
this.logger.error(
`Invalid OTP for user with phone number ${verifyUserDto.countryCode + verifyUserDto.phoneNumber}`,
);
throw new BadRequestException('USERS.INVALID_OTP');
throw new BadRequestException('OTP.INVALID_OTP');
}
if (user.isPhoneVerified) {
@ -108,14 +108,14 @@ export class AuthService {
if (user.email) {
this.logger.error(`Email already set for user with id ${userId}`);
throw new BadRequestException('USERS.EMAIL_ALREADY_SET');
throw new BadRequestException('USER.EMAIL_ALREADY_SET');
}
const existingUser = await this.userService.findUser({ email });
if (existingUser) {
this.logger.error(`Email ${email} already taken`);
throw new BadRequestException('USERS.EMAIL_ALREADY_TAKEN');
throw new BadRequestException('USER.EMAIL_ALREADY_TAKEN');
}
return this.userService.setEmail(userId, email);
@ -127,7 +127,7 @@ export class AuthService {
if (user.password) {
this.logger.error(`Passcode already set for user with id ${userId}`);
throw new BadRequestException('USERS.PASSCODE_ALREADY_SET');
throw new BadRequestException('AUTH.PASSCODE_ALREADY_SET');
}
const salt = bcrypt.genSaltSync(SALT_ROUNDS);
const hashedPasscode = bcrypt.hashSync(passcode, salt);
@ -141,14 +141,14 @@ export class AuthService {
if (user.phoneNumber || user.countryCode) {
this.logger.error(`Phone number already set for user with id ${userId}`);
throw new BadRequestException('USERS.PHONE_NUMBER_ALREADY_SET');
throw new BadRequestException('USER.PHONE_NUMBER_ALREADY_SET');
}
const existingUser = await this.userService.findUser({ phoneNumber, countryCode });
if (existingUser) {
this.logger.error(`Phone number ${countryCode + phoneNumber} already taken`);
throw new BadRequestException('USERS.PHONE_NUMBER_ALREADY_TAKEN');
throw new BadRequestException('USER.PHONE_NUMBER_ALREADY_TAKEN');
}
await this.userService.setPhoneNumber(userId, phoneNumber, countryCode);
@ -171,7 +171,7 @@ export class AuthService {
if (!isOtpValid) {
this.logger.error(`Invalid OTP for user with id ${userId}`);
throw new BadRequestException('USERS.INVALID_OTP');
throw new BadRequestException('OTP.INVALID_OTP');
}
return this.userService.verifyPhoneNumber(userId);
@ -220,7 +220,7 @@ export class AuthService {
if (!user.isProfileCompleted) {
this.logger.error(`Profile not completed for user with email ${email}`);
throw new BadRequestException('USERS.PROFILE_NOT_COMPLETED');
throw new BadRequestException('USER.PROFILE_NOT_COMPLETED');
}
return this.otpService.generateAndSendOtp({
@ -236,7 +236,7 @@ export class AuthService {
const user = await this.userService.findUserOrThrow({ email });
if (!user.isProfileCompleted) {
this.logger.error(`Profile not completed for user with email ${email}`);
throw new BadRequestException('USERS.PROFILE_NOT_COMPLETED');
throw new BadRequestException('USER.PROFILE_NOT_COMPLETED');
}
const isOtpValid = await this.otpService.verifyOtp({
userId: user.id,
@ -247,7 +247,7 @@ export class AuthService {
if (!isOtpValid) {
this.logger.error(`Invalid OTP for user with email ${email}`);
throw new BadRequestException('USERS.INVALID_OTP');
throw new BadRequestException('OTP.INVALID_OTP');
}
this.validatePassword(password, confirmPassword, user);