[Vuejs]-Vue, how to handle errors when using axios calls

4👍

Question: Why did you added:

   .then(response => response)
   .catch(error => error);

in your network.js file?

I guess You have some misunderstanding of Promise.

From the API Promise.prototype.then will return an other promise. This new Promise will serve either as a way to compose something to do on success or catch exception.

From the API Promise.prototype.catch will return an other promise. This new Promise is a bit different. From the doc:

The Promise returned by catch() is rejected if onRejected throws an error or returns a Promise which is itself rejected; otherwise, it is resolved.

So in your case it will call the resolve from the next then call. Unless you throw error in the network.js file which is pointless.

Remove the 2 line in the network.js file and you will have your intended behaviour.

👤mathk

Leave a comment