the http request goes directly to the catch method of the promise, not to then

My Vuejs page is inlined into the app and the http request goes directly to the catch method of the promise, not to then.
here is the code:

queryPayStatus() {
  let vm = this;
  vm.$hms.loading.show();
  vm.$http.get(url)
    .then(response => {
      // not come in
      console.log(response);
      vm.$hms.loading.hide();
    })
    .catch((error) => {
      // goes directly here
      console.log(error);
      vm.$hms.loading.hide();
    });
}

Has anyone had a similar experience?
Does anyone have a solution?
I’d really appreciate it.

  • 1

    The question implies that it is maybe a common JS problem that then/catch somehow always executes catch and there exists a generic solution. There is not. It is caused by the unique circumstances of your app which we know nothing about. We don’t know what $http is. Is it a wrapper for fetch? axios? Don’t know what URL you’re trying to reach and whether it’s an API endpoint or something else, or what the expected response is. If it’s going to the catch block, there must be an error given. What is the error? It seems prudent to include such information.

    – 

  • Really, the code is working as it should. The point of then/catch is that catch() will run instead of then() in the case of an error. fix the error and then it will execute then() instead.

    – 

Leave a Comment