audiobookshelf/client/plugins/axios.js

21 lines
654 B
JavaScript
Raw Normal View History

2021-08-18 00:01:11 +02:00
export default function ({ $axios, store }) {
$axios.onRequest(config => {
if (config.url.startsWith('http:') || config.url.startsWith('https:')) {
return
}
var bearerToken = store.state.user.user ? store.state.user.user.token : null
2021-08-18 00:01:11 +02:00
if (bearerToken) {
config.headers.common['Authorization'] = `Bearer ${bearerToken}`
}
if (process.env.NODE_ENV === 'development') {
config.url = `/dev${config.url}`
console.log('Making request to ' + config.url)
2021-08-18 00:01:11 +02:00
}
})
$axios.onError(error => {
const code = parseInt(error.response && error.response.status)
console.error('Axios error code', code)
})
}