paascloud/paascloud-master · error · ValidateCodeException
获取验证码的值失败
Error message
获取验证码的值失败
What it means
AbstractValidateCodeProcessor.check reads the expected code parameter from the HTTP request using ServletRequestUtils.getStringParameter. If the parameter is entirely absent (ServletRequestBindingException), a ValidateCodeException '获取验证码的值失败' is thrown.
Solutions
- Send the parameter named exactly like codeType.getParamNameOnValidate() (e.g. smsCode) as a form field or query param
- Fix the frontend form field name to match the configured ValidateCodeProperties
- If submitting JSON, ensure it is converted to form/query parameters before the filter runs
- Check gateways/filters are not stripping the parameter
Example fix
// before POST /auth/form body: username=a&password=b (missing smsCode) // after POST /auth/form body: username=a&password=b&smsCode=123456
Defensive patterns
Strategy: validation
Validate before calling
if (request.getParameter("smsCode") == null) { throw new IllegalArgumentException("缺少验证码参数"); } Try / catch
try { processor.validate(new ServletWebRequest(request)); } catch (ValidateCodeException e) { return errorResponse(e.getMessage()); } Prevention
- Match frontend field names to getParamNameOnValidate()
- Send codes as form/query params, not JSON bodies, unless the filter parses JSON
- Integration-test the full login form flow
When it happens
Trigger: Submitting a login/form request without the validate-code parameter named by codeType.getParamNameOnValidate() (e.g. no 'smsCode' or 'imageCode' request parameter).
Common situations: Frontend form field name doesn't match the configured param name; request sent as JSON body while the filter reads query/form parameters; validate-code step skipped or parameter dropped by a proxy/gateway.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/7018ebd1240f3919.
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:137
}
/**
* Check.
*
* @param request the request
*/
@SuppressWarnings("unchecked")
@Override
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)