fix(Question): Handle unexpected state handling issues when CAPTCHA and draft functions are mixed together.

This commit is contained in:
haitaoo 2023-08-01 14:44:36 +08:00
parent 601721a921
commit 9184b9b416
2 changed files with 11 additions and 14 deletions

View File

@ -192,7 +192,7 @@ const Comment = ({ objectId, mode, commentId }) => {
if (ex.isError) {
const captchaErr = addCaptcha.handleCaptchaError(ex.list);
// If it is not a CAPTCHA error, leave it to the subsequent error handling logic to continue processing.
if (!captchaErr || captchaErr.error_msg !== ex.msg) {
if (!(captchaErr && ex.list.length === 1)) {
return Promise.reject(ex);
}
}

View File

@ -244,7 +244,6 @@ const Ask = () => {
};
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
contentChangedRef.current = false;
event.preventDefault();
event.stopPropagation();
@ -256,6 +255,7 @@ const Ask = () => {
if (isEdit) {
editCaptcha.check(() => {
contentChangedRef.current = false;
const ep = {
...params,
id: qid,
@ -283,6 +283,7 @@ const Ask = () => {
});
} else {
saveCaptcha.check(async () => {
contentChangedRef.current = false;
const imgCode = saveCaptcha.getCaptcha();
if (imgCode.verify) {
params.captcha_code = imgCode.captcha_code;
@ -295,26 +296,22 @@ const Ask = () => {
answer_content: formData.answer_content.value,
}).catch((err) => {
if (err.isError) {
saveCaptcha.handleCaptchaError(err.list);
const captchaErr = saveCaptcha.handleCaptchaError(err.list);
if (!(captchaErr && err.list.length === 1)) {
const data = handleFormError(err, formData);
if (data.keys.includes('captcha')) {
delete data.captcha_code;
delete data.captcha_id;
}
setFormData({ ...data });
}
}
});
} else {
res = await saveQuestion(params).catch((err) => {
if (err.isError) {
saveCaptcha.handleCaptchaError(err.list);
const captchaErr = saveCaptcha.handleCaptchaError(err.list);
if (!(captchaErr && err.list.length === 1)) {
const data = handleFormError(err, formData);
if (data.keys.includes('captcha')) {
delete data.captcha_code;
delete data.captcha_id;
}
setFormData({ ...data });
}
}
});
}