aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-03-02 23:05:07 +0800
committerGitHub <noreply@github.com>2024-03-02 15:05:07 +0000
commit27deea7330f83ddb37c918afbb4159053d8847cb (patch)
treec55636fff59079106a013430076817f9a380f356 /web_src/js
parentcc27b50bdf9d1e2b02c91d7c4d338e01408e8522 (diff)
downloadgitea-27deea7330f83ddb37c918afbb4159053d8847cb.tar.gz
gitea-27deea7330f83ddb37c918afbb4159053d8847cb.zip
Make PR form use toast to show error message (#29545)
![image](https://github.com/go-gitea/gitea/assets/2114189/b7a14ed6-db89-4f21-a590-66cd33307233)
Diffstat (limited to 'web_src/js')
-rw-r--r--web_src/js/features/common-global.js11
-rw-r--r--web_src/js/modules/toast.js5
2 files changed, 10 insertions, 6 deletions
diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js
index f90591aff3..c53d43cbb2 100644
--- a/web_src/js/features/common-global.js
+++ b/web_src/js/features/common-global.js
@@ -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) {
diff --git a/web_src/js/modules/toast.js b/web_src/js/modules/toast.js
index fa075aed48..d64359799c 100644
--- a/web_src/js/modules/toast.js
+++ b/web_src/js/modules/toast.js
@@ -21,13 +21,12 @@ const levels = {
};
// See https://github.com/apvarun/toastify-js#api for options
-function showToast(message, level, {gravity, position, duration, ...other} = {}) {
+function showToast(message, level, {gravity, position, duration, useHtmlBody, ...other} = {}) {
const {icon, background, duration: levelDuration} = levels[level ?? 'info'];
-
const toast = Toastify({
text: `
<div class='toast-icon'>${svg(icon)}</div>
- <div class='toast-body'>${htmlEscape(message)}</div>
+ <div class='toast-body'>${useHtmlBody ? message : htmlEscape(message)}</div>
<button class='toast-close'>${svg('octicon-x')}</button>
`,
escapeMarkup: false,