2017-11-05 13 views
0

私のアプリケーションは、異なるアクションから同時に複数のAPI呼び出しを行います。 4/12のアクションがエラー応答を返すと仮定し、ストアはすべてのエラーメッセージ(4つのエラーメッセージの配列)で更新を取得する必要があります。最後に、ヘッダーに4つのエラー ポップアップをすべて表示する必要があります。私は控え目なキャッチについて聞いた。誰もがサンプルコードで説明することができます。React Reduxアプリケーションでの一般的なエラー処理

答えて

2

あなたはミドルウェア、

import { createStore, applyMiddleware } from 'redux'; 

import reduxCatch from 'redux-catch'; 

import reducer from './reducer'; 

function errorHandler(error, getState, lastAction, dispatch) { 
    console.error(error); 
    console.debug('current state', getState()); 
    console.debug('last action was', lastAction); 
    // optionally dispatch an action due to the error using the dispatch parameter 
} 

const store = createStore(reducer, applyMiddleware(
    reduxCatch(errorHandler) 
)); 

を使用している場合Redux-catchに関する詳細なドキュメントを参照してください。また

、これらの質問を確認してください。

redux-promise with Axios, and how do deal with errors?

Best practice to handle errors in Redux and React

関連する問題