diff --git a/src/App.svelte b/src/App.svelte index 2251362..f98a6b9 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -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) + } } }) diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000..0cbbb33 --- /dev/null +++ b/src/util.js @@ -0,0 +1,8 @@ +'use strict' + +export function sleep(ms) { + const p = new Promise((resolve, reject) => { + setTimeout(resolve, ms) + }) + return p +}