elbywan / wretch-middlewares

Collection of middlewares for the Wretch library. 🎁
MIT License
47 stars 7 forks source link

Retry: handle the error edge cases #12

Closed gutenye closed 5 years ago

gutenye commented 5 years ago

Fixes

TypeError: Cannot read property 'ok' of undefined
    at /Users/guten/data/dev/learn/node_modules/wretch/dist/bundle/wretch.js:1:4803
    at processTicksAndRejections (internal/process/task_queues.js:82:5)

to the source

To reproduce

const { retry } = require('wretch-middlewares')
wretch().url(url).middlewares([
  retry({
    retryOnNetworkError: true,
  }),
  next => (url, options) => {
    // custom api error, simplified for demo purpose
    throw new Error('foo')
  }
]).get().json()

Because

line-120 miss one case when checkStatus(null, error) is called and done is false

gutenye commented 5 years ago

@elbywan Could you please publish a new version? My project depends on the changes. Thanks

elbywan commented 5 years ago

@gutenye Sure! I'll do that in a couple of hours (I don't have access right now). In the meantime, you can yarn add https://github.com/elbywan/wretch-middlewares/ if you are in a rush.

elbywan commented 5 years ago

@gutenye Just released v0.1.11.

gutenye commented 5 years ago

Thanks!