Skip to content

Commit 88353df

Browse files
committed
perf: update error msg, clean html tags
1 parent 549adf1 commit 88353df

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/utils/request.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ function isFieldErrorValue(value) {
138138
return typeof value === 'string' || Array.isArray(value) || isPlainObject(value)
139139
}
140140

141+
function stripHtmlTags(text) {
142+
if (typeof text !== 'string') {
143+
return text
144+
}
145+
const cleanedText = text.replace(/<[^>]*>/g, '').trim()
146+
return cleanedText || text
147+
}
148+
141149
function isFieldErrorHandledByForm(response) {
142150
const data = response.data
143151
const fields = response.config?.fieldErrorFields || []
@@ -174,14 +182,15 @@ export function flashErrorMsg({ response, error }) {
174182
if (!response.config.disableFlashErrorMsg) {
175183
const responseErrorMsg = getErrorResponseMsg(error)
176184
const msg = responseErrorMsg || error.message
185+
const displayMsg = stripHtmlTags(msg)
177186

178187
if (response.status === 403 && msg === 'CSRF Failed: CSRF token missing.') {
179188
setTimeout(() => {
180189
logout()
181190
}, 1000)
182191
}
183192
message({
184-
message: msg,
193+
message: displayMsg,
185194
type: 'error',
186195
duration: 5 * 1000
187196
})

0 commit comments

Comments
 (0)