title | description |
---|---|
Hooks |
Hooks with arguments. |
The arguments
listed below are those your hook will receive when it's called.
- arguments:
(config)
Example:
export default function ({ $http }) {
$http.onRequest(config => {
console.log('Making request to ' + config.url)
})
}
See here for advanced usage.
- arguments:
(request, options, response)
Example:
export default function ({ $http }) {
$http.onResponse((req, options, res) => {
console.log('Making request to ' + req.url)
console.log('Options :', options)
console.log('Response data :', res.body)
})
}
See here for advanced usage.
- arguments:
(error)
If the error originated from a request.
Example:
export default function ({ $http, redirect }) {
$http.onError((err) => {
// In case of unauthorized, redirect to a specific page
if (error.statusCode === 401) {
redirect('/401')
}
})
}
Available properties:
error.statusCode
(may be undefined)error.response?.data
(may be undefined)
You can optionally return a value or promise that can resolve for fallback response. If hook returns any value, other hooks won't be called.
See here for advanced usage.