fix:syncBook请求加自动重试,解决unexpected end of stream

This commit is contained in:
ShenQiLun 2026-06-26 13:04:48 +08:00
parent 07d2277664
commit 1de5078104

View File

@ -2161,18 +2161,14 @@ export default {
console.log('【syncBook】请求地址:', apiUrl) console.log('【syncBook】请求地址:', apiUrl)
console.log('【syncBook】请求参数:', params) console.log('【syncBook】请求参数:', params)
const res = await new Promise(function (resolve, reject) { const res = await this.requestWithRetry({
uni.request({ url: apiUrl,
url: apiUrl, method: 'POST',
method: 'POST', header: {
header: { 'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer ' + token
'Authorization': 'Bearer ' + token },
}, data: formBody
data: formBody,
success: function (r) { resolve(r) },
fail: function (e) { reject(e) }
})
}) })
console.log('【syncBook】返回值:', res.statusCode, res.data) console.log('【syncBook】返回值:', res.statusCode, res.data)
@ -2330,18 +2326,14 @@ export default {
console.log('【syncBook】请求地址:', apiUrl) console.log('【syncBook】请求地址:', apiUrl)
console.log('【syncBook】请求参数:', params) console.log('【syncBook】请求参数:', params)
const res = await new Promise(function (resolve, reject) { const res = await this.requestWithRetry({
uni.request({ url: apiUrl,
url: apiUrl, method: 'POST',
method: 'POST', header: {
header: { 'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer ' + token
'Authorization': 'Bearer ' + token },
}, data: formBody
data: formBody,
success: function (r) { resolve(r) },
fail: function (e) { reject(e) }
})
}) })
console.log('【syncBook】返回值:', res.statusCode, res.data) console.log('【syncBook】返回值:', res.statusCode, res.data)
@ -2546,6 +2538,32 @@ export default {
} }
}, },
// 2
requestWithRetry(options, maxRetries) {
if (maxRetries === undefined) maxRetries = 2
var that = this
return new Promise(function (resolve, reject) {
var doRequest = function (attempt) {
uni.request({
url: options.url,
method: options.method,
header: options.header,
data: options.data,
success: function (r) { resolve(r) },
fail: function (e) {
if (attempt < maxRetries) {
console.log('【请求重试】第' + (attempt + 1) + '次失败1秒后重试...', e.errMsg)
setTimeout(function () { doRequest(attempt + 1) }, 1000)
} else {
reject(e)
}
}
})
}
doRequest(0)
})
},
// /+releaserelease // /+releaserelease
async appendWaveItem(warehouseData, productId, stock, price) { async appendWaveItem(warehouseData, productId, stock, price) {
var timestamp = String(Math.floor(Date.now() / 1000)) var timestamp = String(Math.floor(Date.now() / 1000))