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

(cherry picked from commit 27deea7330f83ddb37c918afbb4159053d8847cb)
This commit is contained in:
parent
d509031e84
commit
221a28436a
7 changed files with 35 additions and 30 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue