【发布时间】:2017-09-17 23:39:42
【问题描述】:
https://github.com/svrcekmichal/redux-axios-middleware 有问题。
我想设置拦截器响应(错误)。但无法成功设置。
这是我的代码:
function interceptorResponse({ dispatch, getState, getAction }, response) {
console.log(response);
}
export const client = axios.create({
baseURL: API_URL,
headers: {
Accept: 'application/json',
},
});
export const clientOptions = {
interceptors: {
request: [interceptorRequest],
response: [interceptorResponse],
},
};
console.log(response) 仅在响应为 200 时才响应。如何将其设置为接受错误响应?
我试过这样设置
function interceptorResponse({ dispatch, getState, getAction }) {
return response => response.data, (error) => {
const meta = error.response.data.meta;
const { code, status } = meta;
console.log(meta);
};
}
但仍然没有显示任何内容。
有什么办法吗?
【问题讨论】:
标签: reactjs react-redux axios