osb/spark/resources/assets/js/interceptors.js

28 lines
689 B
JavaScript
Raw Normal View History

2017-11-03 05:26:07 +00:00
module.exports = (request, next) => {
if (Cookies.get('XSRF-TOKEN') !== undefined) {
request.headers.set('X-XSRF-TOKEN', Cookies.get('XSRF-TOKEN'));
}
request.headers.set('X-CSRF-TOKEN', Spark.csrfToken);
/**
* Intercept the incoming responses.
*
* Handle any unexpected HTTP errors and pop up modals, etc.
*/
next(response => {
switch (response.status) {
case 401:
Vue.http.get('/logout');
$('#modal-session-expired').modal('show');
break;
case 402:
window.location = '/settings#/subscription';
break;
}
});
};