diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 272e6f1c44..e292b4b3d3 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -182,12 +182,18 @@ const initChannels = async () => { // default (none), group, dm type - await channels.set( - (await getChannels(localStorage.token)).sort( - (a, b) => - ['', null, 'group', 'dm'].indexOf(a.type) - ['', null, 'group', 'dm'].indexOf(b.type) - ) - ); + const res = await getChannels(localStorage.token).catch((error) => { + return null; + }); + + if (res) { + await channels.set( + res.sort( + (a, b) => + ['', null, 'group', 'dm'].indexOf(a.type) - ['', null, 'group', 'dm'].indexOf(b.type) + ) + ); + } }; const initChatList = async () => { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index c4a8b6c5b2..288a0668a2 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -487,12 +487,19 @@ // handle channel created event if (event.data?.type === 'channel:created') { - await channels.set( - (await getChannels(localStorage.token)).sort( - (a, b) => - ['', null, 'group', 'dm'].indexOf(a.type) - ['', null, 'group', 'dm'].indexOf(b.type) - ) - ); + const res = await getChannels(localStorage.token).catch(async (error) => { + return null; + }); + + if (res) { + await channels.set( + res.sort( + (a, b) => + ['', null, 'group', 'dm'].indexOf(a.type) - ['', null, 'group', 'dm'].indexOf(b.type) + ) + ); + } + return; } @@ -531,13 +538,19 @@ }) ); } else { - await channels.set( - (await getChannels(localStorage.token)).sort( - (a, b) => - ['', null, 'group', 'dm'].indexOf(a.type) - - ['', null, 'group', 'dm'].indexOf(b.type) - ) - ); + const res = await getChannels(localStorage.token).catch(async (error) => { + return null; + }); + + if (res) { + await channels.set( + res.sort( + (a, b) => + ['', null, 'group', 'dm'].indexOf(a.type) - + ['', null, 'group', 'dm'].indexOf(b.type) + ) + ); + } } }