paascloud/paascloud-master · error · ValidateCodeException
验证码已过期
Error message
验证码已过期
What it means
check compares the submitted code against the code stored in the ValidateCodeRepository. If no code exists in the repository or ValidateCode.isExpired() is true, the stored code is removed and '<TYPE>验证码已过期' is thrown.
Solutions
- Re-request a new validate code and submit it promptly
- Increase expireSeconds in ValidateCodeProperties if the TTL is too short
- Ensure deviceId header is stable per device so codes aren't overwritten
- Check Redis persistence/eviction settings if codes vanish early
Example fix
// before security.code.sms.expireSeconds=30 // after security.code.sms.expireSeconds=300
Defensive patterns
Strategy: retry
Try / catch
try { processor.validate(request); } catch (ValidateCodeException e) { if (e.getMessage().contains("已过期")) { promptUserToResendCode(); } } Prevention
- Set generous but sane expireSeconds values
- Prompt users to request a new code on expiry
- Keep deviceId stable so keys aren't lost
- Monitor Redis eviction policies
When it happens
Trigger: User waits past the code's expireSeconds TTL before submitting; no code was ever generated for this device/session; Redis restarted or the key was evicted (session/redis repository).
Common situations: Long delay between requesting and entering the SMS code; multiple devices sharing a deviceId overwriting each other's code; Redis maxmemory eviction; user requesting a new code then submitting the old one.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/53f68f216b5003f7.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/validate/code/impl/AbstractValidateCodeProcessor.java:146
public void check(ServletWebRequest request) {
ValidateCodeType codeType = getValidateCodeType();
C codeInSession = (C) validateCodeRepository.get(request, codeType);
String codeInRequest;
try {
codeInRequest = ServletRequestUtils.getStringParameter(request.getRequest(), codeType.getParamNameOnValidate());
} catch (ServletRequestBindingException e) {
throw new ValidateCodeException("获取验证码的值失败");
}
if (StringUtils.isBlank(codeInRequest)) {
throw new ValidateCodeException(codeType + "验证码的值不能为空");
}
if (codeInSession == null || codeInSession.isExpired()) {
validateCodeRepository.remove(request, codeType);
throw new ValidateCodeException(codeType + "验证码已过期");
}
if (!StringUtils.equals(codeInSession.getCode(), codeInRequest)) {
throw new ValidateCodeException(codeType + "验证码不匹配");
}
}
}
View on GitHub (pinned to 781281a950)