redux-axios-middleware
redux-axios-middleware copied to clipboard
Action returned by promise not put through middleware
I have a middleware which formats API responses. Is it possible to actions returned by calling .then
/.catch
on the request action to be put through that middleware?
Example:
action/login.js
export const logIn = (username, password) => {
const action = {
types: [LOG_IN, LOG_IN_SUCCESS, LOG_IN_FAIL],
payload: {
request: {
// request data
}
},
};
return dispatch => dispatch(action);
};
components/LogIn.js
class LogIn extends Component {
submitForm = (event) => {
const { logIn } = this.props;
const { username, password } = this.state;
event.preventDefault();
logIn(username, password)
.catch(failAction => console.log(failAction)) // <---
};
// render and stuff
}
failAction
is "raw" action, meaning it didn't go through the middleware. Is there a possiblity to change that, or is formatting manually each time the only option?