svrcekmichal / redux-axios-middleware

Redux middleware for fetching data with axios HTTP client
MIT License
920 stars 96 forks source link

Promise not rejected on api error #39

Closed mxaly closed 7 years ago

mxaly commented 7 years ago

Hi, i'm trying to catch api error using axios-middleware server is responding with 404 however, promise is resolved instead of beeing rejected. note that it's wrapped with other promise:

this: is not working:

Keychain
  .getGenericPassword()
  .then((credentials) => {
    return this.props.authProps(credentials.password).catch(() => {
      // handle error
    })
  })

workaround for this is to check in then callback if there is error key

Keychain
  .getGenericPassword()
  .then((credentials) => {
    return this.props.authProps(credentials.password).then((payload) => {
      if(!payload.error) { 
        // handle error 
      }
  })

Actions are dispatched correctly to store, just problem with this promise

svrcekmichal commented 7 years ago

Hi @mxaly it's not workaround, it's intended. You can usereturnRejectedPromiseOnError option to do what you need.

mxaly commented 7 years ago

Right, i missed that when looking at middleware options. It's probably good to mention that here: https://github.com/svrcekmichal/redux-axios-middleware/blame/master/README.md#L77 as this example made me think that reject for api error is the default behavior.

anyway, thank for help, closing:)