yikart/AiToEarn · error · AppHttpException
ErrHttpBack.err_user_code_nohad
ErrHttpBack.err_user_code_nohad
Error message
err_user_code_nohad
What it means
updatePhone validates the SMS code via loginService.verifyPhoneCode(phone, code, LoginTypeCacheKey.Code); a falsy result (missing, expired, or wrong code) throws err_user_code_nohad and the phone is not updated.
Source
Thrown at project/aitoearn-electron/server/src/user/user.controller.ts:85
}
@ApiOperation({
summary: '用户更新自己的电话号码',
description: '和手机验证码登录使用同一个验证码',
})
@Put('updatePhone')
async updatePhone(
@GetToken() token: TokenInfo,
@Body() body: LoginByPhoneDto,
) {
const { phone, code } = body;
const res = await this.loginService.verifyPhoneCode(
phone,
code,
LoginTypeCacheKey.Code,
);
if (!res) throw new AppHttpException(ErrHttpBack.err_user_code_nohad);
return await this.userService.updateUserPhone(token.id, phone);
}
}
View on GitHub (pinned to d3aa8bea5b)
Solutions
- Re-request a fresh verification code and submit it within 5 minutes
- Check the code matches the most recent SMS for that phone
- If testing outside production, use the returned/debug code instead of guessing
- Verify Redis is running and persistent enough for the 5-minute window
Example fix
// before await userApi.updatePhone(phone, oldCode); // expired // after await loginService.postPhoneLoginCode(phone); // fresh code const fresh = promptForCode(); await userApi.updatePhone(phone, fresh);
Defensive patterns
Strategy: validation
Validate before calling
const stored = await redisService.get(`login:code:${phone}`);
if (!stored) await loginService.postPhoneLoginCode(phone); // refresh code first Try / catch
try {
await userApi.updatePhone(phone, code);
} catch (e) {
if (e.response?.message === 'err_user_code_nohad') {
await loginService.postPhoneLoginCode(phone); // resend then retry
}
} Prevention
- Submit codes within the 5-minute TTL
- Always use the latest SMS code after a resend
- Show a countdown timer so users know when codes expire
When it happens
Trigger: PUT update-phone where the submitted code doesn't match the Redis value for that phone, or the 5-minute TTL expired.
Common situations: User typed the code wrong or waited >5 minutes; user requested a new code but entered the old one; dev environment where no SMS was actually sent; Redis restarted/flushed losing the key.
Related errors
- ErrHttpBack.err_user_code_had
- ErrHttpBack.err_user_code_nohad
- ResponseCode.ChannelAuthSessionInvalid
- 无效的状态参数或状态已过期
- 状态数据不完整
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/e6ae09500ce58fbf.
Report an issue: GitHub.