mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-24 19:11:44 +01:00
22 lines
752 B
JavaScript
22 lines
752 B
JavaScript
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
|
|
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)
|
|
}
|
|
})
|
|
|
|
$axios.onError(error => {
|
|
const code = parseInt(error.response && error.response.status)
|
|
const message = error.response ? error.response.data || 'Unknown Error' : 'Unknown Error'
|
|
console.error('Axios error', code, message)
|
|
})
|
|
} |