catch some js network errors

This commit is contained in:
Your Name 2022-07-21 09:47:33 -04:00
parent c06f7e1148
commit e08667ab8a
2 changed files with 13 additions and 3 deletions

View file

@ -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');

View file

@ -56,7 +56,7 @@
我的时间轴
</h5>
</div> -->
<ul class="entity-list__entities" hx-indicator=".htmx-indicator">
<ul class="entity-list__entities">
<div hx-get="{% url 'timeline:data' %}" hx-trigger="revealed" hx-swap="outerHTML"></div>
</ul>
</div>