'My order action is not working `const { data } = await axios.post('/api/v1/order/new', order, config)` returns error code 500 internal server error
This is the orderActions.js
console.log('test1');
export const createOrder = (order) => async (dispatch, getState) => {
try {
console.log('test2');
dispatch({ type: CREATE_ORDER_REQUEST })
console.log('test3');
const config = {
headers: {
'Content-Type': 'application/json'
}
}
console.log('test4');
const { data } = await axios.post('/api/v1/order/new', order, config)
dispatch({
type: CREATE_ORDER_SUCCESS,
payload: data
})
console.log('test5');
} catch (error) {
dispatch({
type: CREATE_ORDER_FAIL,
payload: error.response.data.message
})
console.log('test55', error);
}
}
console.log('test6', createOrder);
My console.log shows
test1
test6 order => async (dispatch, getState) => {.....}
test2
test3
test4
but test5 doesnt show and i cant create a new order for my products
Solution 1:[1]
I think you need to await createOrder in log6.
And you need to call createOrder as a function and pass in the order.
console.log('test6', await createOrder(anOrder))
Except, you say you get a 500 internal server error? Not sure how that's happening...
And shouldn't the method signature be like this?
export const createOrder = async (order, dispatch, getState) => {
Maybe I'm skimming the code too quickly...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dave |
