Make PR form use toast to show error message (#29545)

![image](b7a14ed6-db89-4f21-a590-66cd33307233)

(cherry picked from commit 27deea7330f83ddb37c918afbb4159053d8847cb)
This commit is contained in:
wxiaoguang 2024-03-02 23:05:07 +08:00 committed by Earl Warren
parent d509031e84
commit 221a28436a
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
7 changed files with 35 additions and 30 deletions

View file

@ -91,19 +91,24 @@ async function fetchActionDoRequest(actionElem, url, opt) {
} else {
window.location.reload();
}
return;
} else if (resp.status >= 400 && resp.status < 500) {
const data = await resp.json();
// the code was quite messy, sometimes the backend uses "err", sometimes it uses "error", and even "user_error"
// but at the moment, as a new approach, we only use "errorMessage" here, backend can use JSONError() to respond.
showErrorToast(data.errorMessage || `server error: ${resp.status}`);
if (data.errorMessage) {
showErrorToast(data.errorMessage, {useHtmlBody: data.renderFormat === 'html'});
} else {
showErrorToast(`server error: ${resp.status}`);
}
} else {
showErrorToast(`server error: ${resp.status}`);
}
} catch (e) {
console.error('error when doRequest', e);
actionElem.classList.remove('is-loading', 'small-loading-icon');
showErrorToast(i18n.network_error);
showErrorToast(`${i18n.network_error} ${e}`);
}
actionElem.classList.remove('is-loading', 'small-loading-icon');
}
async function formFetchAction(e) {