Skip to content

Commit efafea1

Browse files
committed
refactor: change all login errors (#748)
1 parent 4234034 commit efafea1

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

src/ErrorCode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum ErrorCode {
2626
UserRoomListNotEmpty, // user room list is not empty.
2727
UserAlreadyBinding, // user already binding
2828
UserPasswordIncorrect, // user password (for update) incorrect
29+
UserOrPasswordIncorrect, // user or password (for login) incorrect
2930

3031
RecordNotFound = 500000, // record info not found
3132

src/v2/services/user/__tests__/email.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ test(`${namespace} - user email not found in login`, async ava => {
153153
() => new UserEmailService(ids(), t).login(`${v4()}@test.com`, v4(), async () => ""),
154154
{
155155
instanceOf: FError,
156-
message: `${Status.Failed}: ${ErrorCode.UserNotFound}`,
156+
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
157157
},
158158
);
159159

@@ -164,7 +164,7 @@ test(`${namespace} - user email not found in login`, async ava => {
164164
() => new UserEmailService(ids(), t).login(userEmailInfo.userEmail, v4(), async () => ""),
165165
{
166166
instanceOf: FError,
167-
message: `${Status.Failed}: ${ErrorCode.UserNotFound}`,
167+
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
168168
},
169169
);
170170

@@ -182,7 +182,7 @@ test(`${namespace} - user email wrong password`, async ava => {
182182
() => new UserEmailService(ids(), t).login(userEmailInfo.userEmail, v4(), async () => ""),
183183
{
184184
instanceOf: FError,
185-
message: `${Status.Failed}: ${ErrorCode.UserPasswordIncorrect}`,
185+
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
186186
},
187187
);
188188

src/v2/services/user/__tests__/phone.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ test(`${namespace} - user phone not found in login`, async ava => {
157157
() => new UserPhoneService(ids(), t).login(randomPhoneNumber(), v4(), async () => ""),
158158
{
159159
instanceOf: FError,
160-
message: `${Status.Failed}: ${ErrorCode.UserNotFound}`,
160+
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
161161
},
162162
);
163163

@@ -168,7 +168,7 @@ test(`${namespace} - user phone not found in login`, async ava => {
168168
() => new UserPhoneService(ids(), t).login(userPhoneInfo.phoneNumber, v4(), async () => ""),
169169
{
170170
instanceOf: FError,
171-
message: `${Status.Failed}: ${ErrorCode.UserNotFound}`,
171+
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
172172
},
173173
);
174174

@@ -186,7 +186,7 @@ test(`${namespace} - user phone wrong password`, async ava => {
186186
() => new UserPhoneService(ids(), t).login(userPhoneInfo.phoneNumber, v4(), async () => ""),
187187
{
188188
instanceOf: FError,
189-
message: `${Status.Failed}: ${ErrorCode.UserPasswordIncorrect}`,
189+
message: `${Status.Failed}: ${ErrorCode.UserOrPasswordIncorrect}`,
190190
},
191191
);
192192

src/v2/services/user/email.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class UserEmailService {
165165
const userUUIDByEmail = await this.userUUIDByEmail(email);
166166
if (!userUUIDByEmail) {
167167
this.logger.info("login email not found", { userEmail: { email } });
168-
throw new FError(ErrorCode.UserNotFound);
168+
throw new FError(ErrorCode.UserOrPasswordIncorrect);
169169
}
170170

171171
const user = await userDAO.findOne(
@@ -177,21 +177,21 @@ export class UserEmailService {
177177
this.logger.info("login email not found user", {
178178
userEmail: { email, userUUIDByEmail },
179179
});
180-
throw new FError(ErrorCode.UserNotFound);
180+
throw new FError(ErrorCode.UserOrPasswordIncorrect);
181181
}
182182

183183
if (!user.user_password) {
184184
this.logger.info("login email user password is null", {
185185
userEmail: { email, userUUIDByEmail },
186186
});
187-
throw new FError(ErrorCode.UserNotFound);
187+
throw new FError(ErrorCode.UserOrPasswordIncorrect);
188188
}
189189

190190
if (user.user_password !== password) {
191191
this.logger.info("login email password incorrect", {
192192
userEmail: { email, userUUIDByEmail },
193193
});
194-
throw new FError(ErrorCode.UserPasswordIncorrect);
194+
throw new FError(ErrorCode.UserOrPasswordIncorrect);
195195
}
196196

197197
return {

src/v2/services/user/phone.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class UserPhoneService {
164164
const userUUIDByPhone = await this.userUUIDByPhone(phone);
165165
if (!userUUIDByPhone) {
166166
this.logger.info("login phone not found", { userPhone: { phone } });
167-
throw new FError(ErrorCode.UserNotFound);
167+
throw new FError(ErrorCode.UserOrPasswordIncorrect);
168168
}
169169

170170
const user = await userDAO.findOne(
@@ -176,22 +176,22 @@ export class UserPhoneService {
176176
this.logger.info("login phone not found user", {
177177
userPhone: { phone, userUUIDByPhone },
178178
});
179-
throw new FError(ErrorCode.UserNotFound);
179+
throw new FError(ErrorCode.UserOrPasswordIncorrect);
180180
}
181181

182182
// User didn't set password, in this case we should not allow login with password
183183
if (!user.user_password) {
184184
this.logger.info("login phone user password is null", {
185185
userPhone: { phone, userUUIDByPhone },
186186
});
187-
throw new FError(ErrorCode.UserNotFound);
187+
throw new FError(ErrorCode.UserOrPasswordIncorrect);
188188
}
189189

190190
if (user.user_password !== password) {
191191
this.logger.info("login phone user password incorrect", {
192192
userPhone: { phone, userUUIDByPhone },
193193
});
194-
throw new FError(ErrorCode.UserPasswordIncorrect);
194+
throw new FError(ErrorCode.UserOrPasswordIncorrect);
195195
}
196196

197197
return {

0 commit comments

Comments
 (0)