mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Make PR form use toast to show error message (#29545)

This commit is contained in:
		| @@ -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) { | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user