Add: handle 401 error
This commit is contained in:
parent
1d18a06e91
commit
ee6d2b805d
|
@ -49,7 +49,9 @@ const sync = (() => {
|
||||||
|
|
||||||
chrome.alarms.onAlarm.addListener(info => {
|
chrome.alarms.onAlarm.addListener(info => {
|
||||||
if (info.name === 'syncNow') {
|
if (info.name === 'syncNow') {
|
||||||
syncNow().catch(console.error);
|
ctrl.syncNow()
|
||||||
|
.catch(handle401Error)
|
||||||
|
.catch(console.error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -58,20 +60,17 @@ const sync = (() => {
|
||||||
stop,
|
stop,
|
||||||
put: ctrl.put,
|
put: ctrl.put,
|
||||||
delete: ctrl.delete,
|
delete: ctrl.delete,
|
||||||
syncNow
|
syncNow: () => ctrl.syncNow().then(handle401Error)
|
||||||
};
|
};
|
||||||
|
|
||||||
function syncNow() {
|
function handle401Error(err) {
|
||||||
return ctrl.syncNow()
|
if (err.code === 401) {
|
||||||
.catch(err => {
|
return tokenManager.revokeToken(currentDrive.name)
|
||||||
if (err.code === 401) {
|
.then(() => {
|
||||||
return tokenManager.revokeToken(currentDrive.name)
|
throw err;
|
||||||
.then(() => {
|
});
|
||||||
throw err;
|
}
|
||||||
});
|
throw err;
|
||||||
}
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function start(name) {
|
function start(name) {
|
||||||
|
@ -81,10 +80,14 @@ const sync = (() => {
|
||||||
ctrl.use(currentDrive);
|
ctrl.use(currentDrive);
|
||||||
return ctrl.start()
|
return ctrl.start()
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err.message);
|
if (/Authorization page could not be loaded/i.test(err.message)) {
|
||||||
|
// FIXME: Chrome always fail at the first login so we try again
|
||||||
|
return ctrl.syncNow();
|
||||||
|
}
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
.catch(handle401Error)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
chrome.alarms.create('syncNow', {periodInMinutes: 30});
|
chrome.alarms.create('syncNow', {periodInMinutes: 30});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user