Ask user to login when session expired

This commit is contained in:
Radhi Fadlillah 2019-05-31 14:14:45 +07:00
parent 6b9c989004
commit 1b74d555ad
4 changed files with 36 additions and 20 deletions

View file

@ -91,7 +91,7 @@
.catch(err => {
this.dialog.loading = false;
err.text().then(msg => {
this.showErrorDialog(`${msg} (${err.status})`);
this.showErrorDialog(msg, err.status);
})
});
}

View file

@ -41,16 +41,32 @@ export default {
if (cfg.secondClick) base.secondClick = cfg.secondClick;
this.dialog = base;
},
showErrorDialog(msg) {
isSessionError(err) {
switch (err.trim().toLowerCase()) {
case "session is not exist":
case "session has been expired":
return true
default:
return false;
}
},
showErrorDialog(msg, status) {
var sessionError = this.isSessionError(msg),
dialogContent = sessionError ? "Session has expired, please login again." : `${msg} (${status})`;
this.showDialog({
visible: true,
title: 'Error',
content: msg,
content: dialogContent,
mainText: 'OK',
mainClick: () => {
this.dialog.visible = false;
if (sessionError) {
document.cookie = "session-id=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
location.href = "/login";
}
}
});
}
},
}
}

View file

@ -209,7 +209,7 @@ export default {
if (err !== skipFetchTags) {
err.text().then(msg => {
this.showErrorDialog(`${msg} (${err.status})`);
this.showErrorDialog(msg, err.status);
})
}
});
@ -313,7 +313,7 @@ export default {
.catch(err => {
this.dialog.loading = false;
err.text().then(msg => {
this.showErrorDialog(`${msg} (${err.status})`);
this.showErrorDialog(msg, err.status);
})
});
}
@ -396,7 +396,7 @@ export default {
.catch(err => {
this.dialog.loading = false;
err.text().then(msg => {
this.showErrorDialog(`${msg} (${err.status})`);
this.showErrorDialog(msg, err.status);
})
});
}
@ -465,7 +465,7 @@ export default {
this.dialog.loading = false;
err.text().then(msg => {
this.showErrorDialog(`${msg} (${err.status})`);
this.showErrorDialog(msg, err.status);
})
});
}
@ -523,7 +523,7 @@ export default {
this.dialog.loading = false;
err.text().then(msg => {
this.showErrorDialog(`${msg} (${err.status})`);
this.showErrorDialog(msg, err.status);
})
});
}
@ -606,7 +606,7 @@ export default {
this.dialog.loading = false;
err.text().then(msg => {
this.showErrorDialog(`${msg} (${err.status})`);
this.showErrorDialog(msg, err.status);
})
});
}

File diff suppressed because one or more lines are too long