3

I have a react app that the user will enter info into a redux form and the function is called. I have a axios post that will not catch an error. I'm not sure what this is happening.

export function vehicleformsubmit(props){   
const input={
        rfidtag: rfidtag.value,
        vin: vin.value,
        vehzone: vehzone.value
};

var request=axios.post(`http://localhost:9000/api/bmwvehicle/create`, input);
return function(dispatch){
    request.then((response) =>{

        dispatch(createVehicleSuccess(response.data, response.status));

    }).catch((error) =>{
        if(error.response){
        dispatch(vehicleHaveError(true));
    }

    });
};

 }

This is that I get back:

    createError.js:16 Uncaught (in promise) Error: Request failed with 
    status code 500
    at createError (createError.js:16)
     at settle (settle.js:18)
    at XMLHttpRequest.handleLoad (xhr.js:77)
Roro
  • 297
  • 5
  • 17
  • Any reason why you're doing `return function(dispatch){...`? – Mrchief Nov 10 '18 at 01:06
  • I thought that was how I would return the dispatch....is this not correct? – Roro Nov 12 '18 at 15:43
  • Depends on your implementation. You're returning a function which _someone_ needs to invoke. Usually you'd just return the promise: `return request.then(...)` – Mrchief Nov 12 '18 at 15:52

0 Answers0