const Authentication = require('./authentication') exports.sendRequest = function(options, isPagination) { let token = Authentication.getToken() let pagination = isPagination if (token) { options.headers = options.headers || {} options.headers['Authorization'] = 'Bearer ' + token } options.extract = function(xhr) { if (xhr.responseText && xhr.responseText.slice(0, 9) === '= 300) { throw out } return out } return m.request(options) .catch(function (error) { if (error.status === 403) { Authentication.clearToken() m.route.set('/', { redirect: m.route.get() }) } if (error.response && error.response.status) { return Promise.reject(error.response) } return Promise.reject(error) }) }