izikandrw
izikandrw

Reputation: 1883

How to detect specific error type using an error type imported from redux-api-middleware

In my react native app, I'm trying to handle custom errors from a third party library: redux-api-middleware. The documentation indicates the custom error type exports but when I import and then check for type equality it does not work. When I debug the imported error type doesn't seem to have any value even though the documentation indicates this should be an export. Am I importing wrong? Comparing wrong? Or something else?

import {RequestError} from 'redux-api-middleware';

const authMiddleware = (store) => (next) => (action) => {
  if (action.error) {
    if (action.payload) { // not all actions have payloads
      if (action.payload instanceof RequestError) {
        showNetworkAlert();
      }
    }
  }

  next(action);
};

Upvotes: 0

Views: 49

Answers (1)

ic3b3rg
ic3b3rg

Reputation: 14927

Your import looks correct - here's where RequestError is exported. I don't have an easy way to test this, but one guess is that you might need to test action.error instead of action.payload, i.e. if (action.error instanceof RequestError) { ... }

Upvotes: 0

Related Questions