mirror of
https://github.com/PaiGramTeam/luoxu-api-pub.git
synced 2024-11-22 07:08:05 +00:00
retry fetching group info
This commit is contained in:
parent
d7cab6461f
commit
f1d931107c
@ -2,6 +2,7 @@
|
||||
import { onMount, setContext } from 'svelte'
|
||||
import Message from './Message.svelte'
|
||||
import Name from './Name.svelte'
|
||||
import { sleep } from './util.js'
|
||||
|
||||
const LUOXU_URL = 'https://lab.lilydjwg.me/luoxu'
|
||||
let groups = []
|
||||
@ -30,11 +31,19 @@
|
||||
|
||||
onMount(async () => {
|
||||
do_hash_search()
|
||||
const res = await fetch(`${LUOXU_URL}/groups`)
|
||||
groups = (await res.json()).groups
|
||||
need_update_title = true
|
||||
if(!group) {
|
||||
group = ''
|
||||
while(true) {
|
||||
try{
|
||||
const res = await fetch(`${LUOXU_URL}/groups`)
|
||||
groups = (await res.json()).groups
|
||||
need_update_title = true
|
||||
if(!group) {
|
||||
group = ''
|
||||
}
|
||||
break
|
||||
}catch(e){
|
||||
console.error('failed to fetch group info, will retry', e)
|
||||
await sleep(1000)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
8
src/util.js
Normal file
8
src/util.js
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
export function sleep(ms) {
|
||||
const p = new Promise((resolve, reject) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
return p
|
||||
}
|
Loading…
Reference in New Issue
Block a user