修复请求超时的逻辑处理Bug
parent
ea10dd68a3
commit
29855b2b6e
|
@ -12,4 +12,5 @@
|
|||
|
||||
### 修复
|
||||
|
||||
- 修复一些小Bug
|
||||
- 修复请求超时的逻辑处理Bug,尝试修复请求无法取消导致的正在播放的歌曲与界面显示的信息不一致的问题
|
||||
- 修复其他一些小Bug
|
||||
|
|
|
@ -18,10 +18,16 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import dnscache from 'dnscache'
|
||||
import { mapMutations, mapGetters, mapActions } from 'vuex'
|
||||
import { rendererOn } from '../common/icp'
|
||||
import { isLinux } from '../common/utils'
|
||||
window.ELECTRON_DISABLE_SECURITY_WARNINGS = process.env.ELECTRON_DISABLE_SECURITY_WARNINGS
|
||||
dnscache({
|
||||
enable: true,
|
||||
ttl: 21600,
|
||||
cachesize: 1000,
|
||||
})
|
||||
let win
|
||||
let body
|
||||
if (!isLinux) {
|
||||
|
|
|
@ -8,10 +8,7 @@ export default {
|
|||
_musicTempSearchRequestObj: null,
|
||||
_musicTempSearchPromiseCancelFn: null,
|
||||
tempSearch(str) {
|
||||
if (this._musicTempSearchRequestObj != null) {
|
||||
cancelHttp(this._musicTempSearchRequestObj)
|
||||
this._musicTempSearchPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
this.cancelTempSearch()
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicTempSearchPromiseCancelFn = reject
|
||||
this._musicTempSearchRequestObj = httpGet(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`, (err, resp, body) => {
|
||||
|
|
|
@ -5,13 +5,6 @@ import { requestMsg } from './message'
|
|||
import { bHh } from './music/options'
|
||||
// import fs from 'fs'
|
||||
|
||||
import dnscache from 'dnscache'
|
||||
dnscache({
|
||||
enable: true,
|
||||
ttl: 21600,
|
||||
cachesize: 1000,
|
||||
})
|
||||
|
||||
const defaultHeaders = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
|
||||
}
|
||||
|
@ -26,7 +19,7 @@ const defaultHeaders = {
|
|||
const buildHttpPromose = (url, options) => {
|
||||
let requestObj
|
||||
let cancelFn
|
||||
const p = new Promise((resolve, reject) => {
|
||||
let p = new Promise((resolve, reject) => {
|
||||
cancelFn = reject
|
||||
debugRequest && console.log(`\n---send request------${url}------------`)
|
||||
requestObj = fetchData(url, options.method, options, (err, resp, body) => {
|
||||
|
@ -36,11 +29,12 @@ const buildHttpPromose = (url, options) => {
|
|||
requestObj = null
|
||||
cancelFn = null
|
||||
if (err) {
|
||||
console.log(err.code)
|
||||
// console.log('出错', err.code)
|
||||
if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') {
|
||||
const { promise, cancelHttp } = httpFetch(url, options)
|
||||
obj.cancelHttp = cancelHttp
|
||||
promise.then()
|
||||
promise.then(resp => resolve(resp)).catch(err => reject(err))
|
||||
return
|
||||
}
|
||||
return reject(err)
|
||||
}
|
||||
|
@ -51,11 +45,11 @@ const buildHttpPromose = (url, options) => {
|
|||
promise: p,
|
||||
cancelHttp() {
|
||||
if (!requestObj) return
|
||||
console.log('cancel')
|
||||
cancelHttp(requestObj)
|
||||
cancelFn(new Error(requestMsg.cancelRequest))
|
||||
cancelHttp(requestObj)
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
p = null
|
||||
},
|
||||
}
|
||||
return obj
|
||||
|
|
Loading…
Reference in New Issue