nfp_sites/app/api/common.js

24 lines
630 B
JavaScript
Raw Normal View History

2019-02-22 14:53:43 +00:00
const m = require('mithril')
const Authentication = require('../authentication')
exports.sendRequest = function(options) {
let token = Authentication.getToken()
if (token) {
options.headers = options.headers || {}
options.headers['Authorization'] = 'Bearer ' + token
}
return m.request(options)
.catch(function (error) {
if (error.code === 403) {
Authentication.clearToken()
m.route.set('/login', { redirect: m.route.get() })
}
2019-09-13 13:33:10 +00:00
if (error.response && error.response.status) {
return Promise.reject(error.response)
}
2019-02-22 14:53:43 +00:00
return Promise.reject(error)
})
}