mirror of https://github.com/sundowndev/http.git
parent
e9e225f142
commit
8e0c0e8c4c
|
@ -151,6 +151,11 @@ requestInterceptor: (config, { store }) => {
|
|||
|
||||
Function for manipulating axios responses.
|
||||
|
||||
### `init`
|
||||
- Default: `null`
|
||||
|
||||
Function `init(axios, ctx)` to do additional things with axios.
|
||||
|
||||
### `errorHandler`
|
||||
- Default: (Return promise rejection with error)
|
||||
|
||||
|
|
|
@ -126,7 +126,12 @@ export default (ctx, inject) => {
|
|||
headers
|
||||
})
|
||||
|
||||
<% if(options.credentials) { %>
|
||||
// Custom init hook
|
||||
<% if (options.init) { %>
|
||||
const initHook = <%= serialize(options.init).replace('init(', 'function(').replace('function function', 'function') %>
|
||||
<% } %>
|
||||
|
||||
<% if (options.credentials) { %>
|
||||
// Send credentials only to relative and API Backend requests
|
||||
axios.interceptors.request.use(config => {
|
||||
if (config.withCredentials === undefined) {
|
||||
|
@ -167,7 +172,7 @@ export default (ctx, inject) => {
|
|||
const resInter = <%= serialize(options.responseInterceptor).replace('responseInterceptor(', 'function(').replace('function function', 'function') %>
|
||||
axios.interceptors.response.use(config => resInter(config, ctx))
|
||||
<% } %>
|
||||
|
||||
|
||||
// Error handler
|
||||
axios.interceptors.response.use(undefined, errorHandler.bind(ctx));
|
||||
|
||||
|
@ -176,6 +181,10 @@ export default (ctx, inject) => {
|
|||
axios.interceptors.response.use(undefined, customErrorHandler.bind(ctx))
|
||||
<% } %>
|
||||
|
||||
<% if (options.init) { %>
|
||||
await initHook(axios, ctx)
|
||||
<% } %>
|
||||
|
||||
// Inject axios to the context as $axios
|
||||
inject('axios', axios)
|
||||
|
||||
|
|
Loading…
Reference in New Issue