I don't think there is a problem with the request because I have used the same request for posting a new character and it succeded. I think the problem is with the response.
Backend using Express and Node
I have an API route which updates a character.
router.put('/:id', (req, res, next) => {
const { id } = req.params;
Promise.all([
updateAbilities(id, req.body.abilities, next),
updateCharacter(id, req.body.name, req.body.img, next),
updateShows(id, req.body.shows, next)
])
.then(values => console.log(values, 'are the values received at put request'))
.then(() => res.redirect('/' + id))
.catch(err => next(err));
})
When I am sending the request using Postman, I am getting the perfect response.
Frontend in React App using Axios
I am performing the same request on a React App using Axios.
export async function updateOne(inputs, cid) {
inputs = {
name: "green latern 2",
abilities: "ring, superpower",
shows: "justice league",
img: "an image",
};
cid = 11;
let err = null
const response = await axios({
method: 'PUT',
url: BASE_URL + cid,
data: inputs
}).catch(e => err = e);
console.log(response, 'was the response');
return;
}
But on doing so, I am getting this error:
Error: Network Error
createError createError.js:16
handleError xhr.js:83
dispatchXhrRequest xhr.js:80
xhrAdapter xhr.js:12
dispatchRequest dispatchRequest.js:52
promise callback*request Axios.js:61
wrap bind.js:9
updateOne apiCalls.js:36
js apiCalls.js:66
Webpack 22
was the response apiCalls.js:42
The Code can be found on GitHub : https://github.com/uinstinct/card_builder
If you need more information, I shall provide what you need. Please a comment for the same