0

I started to learn how to use the Vue.js framework a little while ago, and I got stuck with this situation.

I use the jQuery.ajax() method to make requests to a web api. For each of these ajax requests (I'll use the login request as an example), in case of error, I redirect the code to a function called callbackError like this:

async login() {
    await $.ajax({
        type: 'post',
        url: `${this.$ROOT_API}/Users/login/${this.username}/${this.password}`,
        dataType: 'text',
        success: this.loginSuccessCallback,
        error: this.callbackError
    });
}

The callbackError() function simply displays an error popup.

callbackError(request, status, error) {
    Swal.fire({
        title: 'Error',
        icon: 'error',
        text: `${request} ${status} ${error}`,
        confirmButtonText: '<i class="fa-solid fa-check"></i>',
        background: this.$COLORS.navbar,
        color: this.$COLORS.font,
        confirmButtonColor: this.$COLORS.primary
    })
}

Now, if I cause an error during the connection by entering a wrong password, the popup is displayed correctly (I know it's not very telling, I'll fix it later).

error popup

But despite the fact that the popup was displayed, which proves that the error was handled, I still have these error messages in the console that tell me that there was an unhandled error:

error messages in the console

Honestly I don't even know what to try to fix the problem I just feel like my browser is blatantly lying to me that I didn't handle the error.

PS : I don't have the Ghostery extension so I don't think it's the same problem as on this question: "A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received", What does that mean?

UPDATE :

I now use the axios library to make my requests to the web api, and it works fine.

async loginAsync() {
    await axios({
        method: 'post',
        url: `api/Users/login/${this.username}/${this.password}`
    })
    .then(response => this.loginSuccessCallback(response))
    .catch(error => this.$CALLBACK_ERROR(error))
}
  • 1
    Have you tried using [.fail()](https://api.jquery.com/deferred.fail/) method in jQuery? – Huy Phạm Dec 14 '22 at 15:07
  • Do you happen to be using an extension called Ghostery? [similar stackoverflow question](https://stackoverflow.com/questions/72494154/a-listener-indicated-an-asynchronous-response-by-returning-true-but-the-messag) – yoduh Dec 14 '22 at 19:19
  • @yoduh I don't have this extension. Do you think that the problem is not actually in my code? – CeFameuxTom Dec 15 '22 at 09:07
  • @HuyPhạm Doesn't the 'error' property of $.ajax() already have the same use? – CeFameuxTom Dec 15 '22 at 09:13
  • 1
    @CeFameuxTom It's deprecated if I remember correctly – Huy Phạm Dec 16 '22 at 18:29
  • @HuyPhạm Well, you were certainly right, I think that's where the mistake came from, because I now use axios and it works well – CeFameuxTom Dec 22 '22 at 09:01

0 Answers0