feat(error-handler): add error handler middleware POC

This commit is contained in:
George Lima 2019-01-30 21:17:47 -03:00
parent ed4ffd92a9
commit 1fcb29f6d2
1 changed files with 22 additions and 0 deletions

22
app/redux/errorHandler.js Normal file
View File

@ -0,0 +1,22 @@
// @flow
import { LOAD_ADDRESSES_ERROR } from './modules/receive';
import { VALIDATE_ADDRESS_ERROR } from './modules/send';
import { LOAD_TRANSACTIONS_ERROR } from './modules/transactions';
import { LOAD_WALLET_SUMMARY_ERROR } from './modules/wallet';
import { showErrorModal } from './modules/app';
import type { Middleware } from '../types/redux';
const ERRORS = [
LOAD_ADDRESSES_ERROR,
VALIDATE_ADDRESS_ERROR,
LOAD_TRANSACTIONS_ERROR,
LOAD_WALLET_SUMMARY_ERROR,
];
export const errorHandler: Middleware = ({ dispatch }) => next => (action) => {
// eslint-disable-next-line max-len
if (ERRORS.includes(action.type)) return dispatch(showErrorModal({ error: action.payload.error || 'Something went wrong!' }));
return next(action);
};