Reputation: 830
const config = {
headers: { "Content-Type": "application/octet-stream" }
}
let files = this.state.files
let promises = []
files.map((item ,index) => {
promises.push(axios.put(this.props.deal.authURL[index], item, config))
})
I get this error:
Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
My aim is to store all the result of the Axios calls inside promises array. And then use Promise.all()
function to resolve all at once. Can't figure why the error is there.
Any sort of help is appreciated. Thanks
Upvotes: 2
Views: 23362
Reputation: 302
RECOMMENDED SOLUTIONS
Like already mentioned above, this error is thrown when we send a malformed request or wrong method or any fault in the body/header.
However, if you have checked all of these, and they are all okay, and you are still getting the error, then chances are you are handling the response wrongly.
How to correct it?
It is always a good idea to console.log(response)
of the request sent, just so we know how to handle the response.
I faced a similar issue today afternoon. After sitting with it for a while, correcting all the methods/request links and things like that, I was still getting an error, then I realised I was handling the responses wrongly.
So, it is always recommended to console.log
the response.
Upvotes: 1
Reputation: 830
this.props.deal.authURL[index]
was returning an undefined url and that was the reason for the random error.
Upvotes: 8