nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

DOMException: The user aborted a request with `onDownloadProgress` and request cancelation #132

Open AlissonRA opened 4 years ago

AlissonRA commented 4 years ago

good afternoon

I am having a problem when trying to cancel a request for aws with the onDownloadProgress () event instantiated!

    const controller = new AbortController ()

    setTimeout (() => {
      console.log ('abort', Date.now ())
      controller.abort ()
    }, 2500)

    try {
      console.log ('request', Date.now ())
      await this. $ http.get ('https://storage-dev-test.s3.us-east-2.amazonaws.com/navicat121_premium_en_x64.exe', {
        signal: controller.signal,
        hooks: {
          beforeRequest: [
            (request) => {
              request.headers.delete ('Authorization')
            }
          ]
        },
        onDownloadProgress: (progress) => {
          console.log (progress)
        }
      }). then (async (responseAWS) => {
        await responseAWS.arrayBuffer (). then ((responseEnd) => {
          console.log (responseEnd)
        })
      })
    } catch (error) {
      console.log ('exception', Date.now ())
      if (error.name === 'AbortError') {
        console.log ('Fetch aborted')
      } else {
        console.error ('Fetch error:', error)
      }
    }

the error returned in the console is as follows:

Uncaught (in promise) DOMException: The user aborted a request.

Now if I remove the code part:

onDownloadProgress: (progress) => {
  console.log (progress)
}

No error is returned on the console. can anybody help me? because I need onDownloadProgress but with the error breaking the code I can't make the necessary finalizations.

Geminii commented 3 years ago

Hi @AlissonRA 👋 I don't understand the options that you passed in your call : await this.$http.get('URL', { OPTIONS }) Relative to the options documentation, there is no configuration for onDownloadProgress.

Maybe you want to add a hook on it ? Currently, there are only 3 hooks supported by http module : onRequest, onResponse & onError.

AlissonRA commented 3 years ago

Hello @Geminii

OnDownloadProgress is not an option for nuxt/http but for Ky. Since that is what nuxt/http uses behind the scenes.

atinux commented 3 years ago

The options are forwarded directly to key, see here.

This error is weird, could you try directly by using ky and confirm there is no error with it?

AlissonRA commented 3 years ago

Hello @Atinux

I tested with the native ky library and got the same error! Now what can I do? Do I have to open an issue there and ask for correction of this error and as soon as it is corrected return here and ask for the package update or wait for your update to resolve the problem?

atinux commented 3 years ago

Exactly @AlissonRA