From e08667ab8a9894120889f990b0e97dedbd24ec62 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 21 Jul 2022 09:47:33 -0400 Subject: [PATCH] catch some js network errors --- common/static/js/mastodon.js | 14 ++++++++++++-- timeline/templates/timeline.html | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/static/js/mastodon.js b/common/static/js/mastodon.js index 2364e730..1f18435b 100644 --- a/common/static/js/mastodon.js +++ b/common/static/js/mastodon.js @@ -56,7 +56,12 @@ const NUMBER_PER_REQUEST = 20 // ] async function getFollowers(id, mastodonURI, token, callback) { const url = mastodonURI + API_FOLLOWERS.replace(":id", id); - const response = await fetch(url+'?limit='+NUMBER_PER_REQUEST, {headers: {'Authorization': 'Bearer ' + token}}); + try { + const response = await fetch(url+'?limit='+NUMBER_PER_REQUEST, {headers: {'Authorization': 'Bearer ' + token}}); + } catch (e) { + console.error('loading followers failed.'); + return; + } const json = await response.json(); let nextUrl = null; let links = response.headers.get('link'); @@ -73,7 +78,12 @@ async function getFollowers(id, mastodonURI, token, callback) { async function getFollowing(id, mastodonURI, token, callback) { const url = mastodonURI + API_FOLLOWING.replace(":id", id); - const response = await fetch(url+'?limit='+NUMBER_PER_REQUEST, {headers: {'Authorization': 'Bearer ' + token}}); + try { + const response = await fetch(url+'?limit='+NUMBER_PER_REQUEST, {headers: {'Authorization': 'Bearer ' + token}}); + } catch (e) { + console.error('loading following failed.'); + return; + } const json = await response.json(); let nextUrl = null; let links = response.headers.get('link'); diff --git a/timeline/templates/timeline.html b/timeline/templates/timeline.html index ca38d6e7..17e89fd8 100644 --- a/timeline/templates/timeline.html +++ b/timeline/templates/timeline.html @@ -56,7 +56,7 @@ 我的时间轴 --> -