Don't crash if instances are unavailable

This commit is contained in:
Cadence Ember 2024-04-22 18:04:28 +12:00
parent 59266a6419
commit 31ba4035b0
1 changed files with 7 additions and 2 deletions

View File

@ -1,4 +1,5 @@
const {request} = require("../utils/request") const {request} = require("../utils/request")
const {log} = require("pinski/util/common")
class InstancesList { class InstancesList {
constructor() { constructor() {
@ -16,9 +17,13 @@ class InstancesList {
*/ */
update() { update() {
return this.inflight = request("https://api.invidious.io/instances.json?sort_by=health").then(res => res.json()).then(list => { return this.inflight = request("https://api.invidious.io/instances.json?sort_by=health").then(res => res.json()).then(list => {
list = list.filter(i => i[1].type === "https").map(i => i[1].uri.replace(/\/+$/, "")) return list.filter(i => i[1].type === "https").map(i => i[1].uri.replace(/\/+$/, ""))
this.list = list }).catch(e => {
log(`[background/instances] ${e.message}`, "warning")
return []
}).then(list => {
this.inflight = null this.inflight = null
this.list = list
return this.list return this.list
}) })
} }