mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-12-23 02:33:18 +00:00
Added checkFetchStatus function and fetch will use it.
This commit is contained in:
parent
368b8d2364
commit
3fee7bb40a
@ -17,9 +17,10 @@ module.exports = class extends Client {
|
|||||||
|
|
||||||
this.funcs = {};
|
this.funcs = {};
|
||||||
this.funcs.check = require('./funcs/check.js');
|
this.funcs.check = require('./funcs/check.js');
|
||||||
|
this.funcs.checkFetchStatus = require('./funcs/checkFetchStatus.js');
|
||||||
|
this.funcs.isDev = require('./funcs/isDev.js');
|
||||||
this.funcs.msToTime = require('./funcs/msToTime.js');
|
this.funcs.msToTime = require('./funcs/msToTime.js');
|
||||||
this.funcs.statisticsUpdate = require('./funcs/statisticsUpdate.js');
|
this.funcs.statisticsUpdate = require('./funcs/statisticsUpdate.js');
|
||||||
this.funcs.isDev = require('./funcs/isDev.js');
|
|
||||||
|
|
||||||
this.config = require('../config.js');
|
this.config = require('../config.js');
|
||||||
this.messages = require('./messages.js');
|
this.messages = require('./messages.js');
|
||||||
|
@ -21,14 +21,20 @@ module.exports = {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
|
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
|
||||||
.then(res => res.json());
|
.then(client.funcs.checkFetchStatus)
|
||||||
} catch (err) {
|
.then(response => response.json());
|
||||||
console.error(err);
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
|
try {
|
||||||
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
|
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
|
||||||
.then(res => res.json());
|
.then(client.funcs.checkFetchStatus)
|
||||||
|
.then(response => response.json());
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
}, 3600000);
|
}, 3600000);
|
||||||
|
|
||||||
if(!client.stations) {
|
if(!client.stations) {
|
||||||
|
7
client/funcs/checkFetchStatus.js
Normal file
7
client/funcs/checkFetchStatus.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module.exports = function (response) {
|
||||||
|
if (response.ok) { // res.status >= 200 && res.status < 300
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw new Error(response.status + " " + response.statusText);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user