|
@@ -162,7 +162,8 @@ http.interceptors.request.use(
|
|
|
raw,
|
|
|
config
|
|
|
}
|
|
|
- // 记录错误
|
|
|
+ // 记录请求备用-签名错误后重试
|
|
|
+
|
|
|
errorData.push({
|
|
|
time: header.timestamp,
|
|
|
url: config.url,
|
|
@@ -228,6 +229,23 @@ http.interceptors.response.use(
|
|
|
return handleRefreshToken(response.config);
|
|
|
}
|
|
|
|
|
|
+ // 签名错误
|
|
|
+ if (response.data.code === 440) {
|
|
|
+ // 更新服务器与用户时间差的值
|
|
|
+ const { setTimeDifference } = useSystem()
|
|
|
+ if (Number(response?.data?.msg)) setTimeDifference(response.data.msg - new Date().getTime())
|
|
|
+ // 请求重试
|
|
|
+ signErrRetry(response.config)
|
|
|
+ // 保存错误信息
|
|
|
+ const _index = errorData.findIndex(e => e.url === config.url && e.time === +config.header.timestamp)
|
|
|
+ if (_index > -1) {
|
|
|
+ const _d = errorData.splice(_index, 1)
|
|
|
+ const _item = _d[0]
|
|
|
+ sendError({ content: JSON.stringify(_item.content), mark: _item.time + '' })
|
|
|
+ }
|
|
|
+ response.config.custom.showError = false // 不弹错误弹窗
|
|
|
+ }
|
|
|
+
|
|
|
// 错误提示
|
|
|
if (response.config.custom.showError) {
|
|
|
if (response.data?.msg === '重复请求,请稍后重试') console.error('前台打印: 重复请求,请稍后重试')
|
|
@@ -241,17 +259,6 @@ http.interceptors.response.use(
|
|
|
}
|
|
|
return Promise.reject(response.data);
|
|
|
}
|
|
|
- const code = response.data.code || 200
|
|
|
-
|
|
|
- const _index = errorData.findIndex(e => e.url === config.url && e.time === +config.header.timestamp)
|
|
|
- if (_index > -1) {
|
|
|
- const _d = errorData.splice(_index, 1)
|
|
|
- const _item = _d[0]
|
|
|
- // 保存错误信息
|
|
|
- if (code === 400) {
|
|
|
- sendError({ content: JSON.stringify(_item.content), mark: _item.time + '' })
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
// 自定义处理【showSuccess 成功提示】:如果需要显示成功提示,则显示成功提示
|
|
|
if (response.config.custom.showSuccess && response.config.custom.successMsg !== '' && response.data.code === 0) {
|
|
@@ -300,6 +307,9 @@ http.interceptors.response.use(
|
|
|
case 429:
|
|
|
errorMessage = '请求频繁, 请稍后再访问';
|
|
|
break;
|
|
|
+ case 440:
|
|
|
+ errorMessage = '网络请求出错'; // 签名异常
|
|
|
+ break;
|
|
|
case 500:
|
|
|
errorMessage = '服务器开小差啦,请稍后再试~';
|
|
|
break;
|
|
@@ -416,6 +426,34 @@ const handleAuthorized = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 处理440签名错误
|
|
|
+*/
|
|
|
+const maxRetries = 2 // 设置签名错误重试请求次数,超出次数弹出错误
|
|
|
+const retryDelay = 1000 // 请求延迟
|
|
|
+const signErrRetry = (config) => {
|
|
|
+ if (config) {
|
|
|
+ if (!config?.custom?.retryCount) {
|
|
|
+ config.custom.retryCount = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ // 超过重试次数
|
|
|
+ if (config.custom.retryCount >= maxRetries) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '网络请求错误!',
|
|
|
+ icon: 'none',
|
|
|
+ mask: false,
|
|
|
+ });
|
|
|
+ return Promise.reject({ statusCode: 440 })
|
|
|
+ }
|
|
|
+ // 重试
|
|
|
+ config.custom.retryCount++
|
|
|
+ setTimeout(() => {
|
|
|
+ return request(config)
|
|
|
+ }, retryDelay)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 触发获取积分
|
|
|
const getIntegral = (url) => {
|
|
|
rewardEventTrackClick(url).then(() => {})
|