fix: retry when personalFM not found data (#1231)

* fix: retry when personalFM not found data

* fix

* fix: retry count
This commit is contained in:
memorydream 2022-01-17 23:23:39 +08:00 committed by GitHub
parent d716bb8cde
commit 75fed70c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,12 @@ const electron =
process.env.IS_ELECTRON === true ? window.require('electron') : null;
const ipcRenderer =
process.env.IS_ELECTRON === true ? electron.ipcRenderer : null;
const delay = ms =>
new Promise(resolve => {
setTimeout(() => {
resolve('');
}, ms);
});
const excludeSaveKeys = [
'_playing',
'_personalFMLoading',
@ -577,12 +583,29 @@ export default class {
this._isPersonalFM = true;
if (!this._personalFMNextTrack) {
this._personalFMLoading = true;
let result = await personalFM().catch(() => null);
let result = null;
let retryCount = 5;
for (; retryCount >= 0; retryCount--) {
result = await personalFM().catch(() => null);
if (!result) {
this._personalFMLoading = false;
if (!result || !result.data) {
store.dispatch('showToast', 'personal fm timeout');
return false;
}
if (result.data?.length > 0) {
break;
} else if (retryCount > 0) {
await delay(1000);
}
}
this._personalFMLoading = false;
if (retryCount < 0) {
let content = '获取私人FM数据时重试次数过多请手动切换下一首';
store.dispatch('showToast', content);
console.log(content);
return false;
}
// 这里只能拿到一条数据
this._personalFMTrack = result.data[0];
} else {