文件读取异常给出提示

This commit is contained in:
bob
2025-04-17 09:57:38 +08:00
parent 8ed65c1358
commit 6d88195590
4 changed files with 6 additions and 8 deletions

View File

@@ -11,7 +11,7 @@ export const getMd5 = (file) => {
resolve(md5)
}
reader.onerror = () => {
reject(new Error('Failed to get md5 of file.'))
reject(new Error('读取文件md5值失败'))
}
})
}

View File

@@ -1,5 +1,3 @@
import { ElMessage } from 'element-plus'
/**
* 流控在duration时间内只允许task任务被执行countLimit次
* @param {*} task 待执行的任务Promise可以是请求或者其他
@@ -11,8 +9,7 @@ export const flowLimiteWrapper = (task, countLimit, duration) => {
let count = 0
return async () => {
if (count >= countLimit) {
ElMessage.warning('请求太过频繁,请稍后再试')
return Promise.reject(new Error('REQUEST_LIMITED')) // 返回一个拒绝的 Promise
return Promise.reject(new Error('请求太过频繁,请稍后再试')) // 返回一个拒绝的 Promise
}
count++

View File

@@ -58,7 +58,7 @@ export const prehandleImage = async (blob, originalWidth = null, originalHeight
resolve(result)
}
} else {
reject(new Error('Failed to generate thumb.'))
reject(new Error('生成缩略图遇到了问题'))
}
},
blob.type,
@@ -66,11 +66,11 @@ export const prehandleImage = async (blob, originalWidth = null, originalHeight
)
}
img.onerror = () => {
reject(new Error('Failed to load image.'))
reject(new Error('加载图片失败'))
}
}
reader.onerror = () => {
reject(new Error('Failed to read file.'))
reject(new Error('读取图片失败'))
}
})
}

View File

@@ -66,6 +66,7 @@ const onSelectedFile = async (file) => {
}
})
} catch (error) {
ElMessage.error(error.message)
return
}