Probably fix HTTP 401

This commit is contained in:
Maks Snegov 2024-04-26 23:45:56 -07:00
parent d19b9ced8f
commit c428e4ab11

View File

@ -129,10 +129,8 @@ async function handleHttpError(e) {
console.log(msg); console.log(msg);
await sendNotification(msg); await sendNotification(msg);
await logOut(); await logOut();
return null;
} else { } else {
console.error(e); console.error(e);
return null;
} }
} }
@ -211,12 +209,16 @@ async function getAvailableDates(consulateId) {
let uri = window.location.pathname + `/days/${consulateId}.json?appointments[expedite]=false` let uri = window.location.pathname + `/days/${consulateId}.json?appointments[expedite]=false`
let dates = fetch(uri, { headers: { "x-requested-with": "XMLHttpRequest" }}) let dates = fetch(uri, { headers: { "x-requested-with": "XMLHttpRequest" }})
.then(d => d.json()) .then(d => d.json())
.catch(async e => {
await handleHttpError(e);
throw e;
})
.then(data => { .then(data => {
let dateList = data.map(item => item.date); let dateList = data.map(item => item.date);
dateList.sort(); dateList.sort();
return dateList; return dateList;
}) })
.catch(async e => handleHttpError(e)); .catch(e => null);
return dates; return dates;
} }
@ -234,8 +236,12 @@ async function getAvailableTimes(consulateId, date) {
let uri = window.location.pathname + `/times/${consulateId}.json?date=${date}&appointments[expedite]=false` let uri = window.location.pathname + `/times/${consulateId}.json?date=${date}&appointments[expedite]=false`
let times = await fetch(uri, { headers: { "x-requested-with": "XMLHttpRequest" } }) let times = await fetch(uri, { headers: { "x-requested-with": "XMLHttpRequest" } })
.then(d => d.json()) .then(d => d.json())
.catch(async e => {
await handleHttpError(e);
throw e;
})
.then(data => data.available_times) .then(data => data.available_times)
.catch(e => handleHttpError(e)); .catch(e => null);
return times; return times;
} }