Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {all, take, fork, put, call, join} from 'redux-saga/effects'
- import {responseErrorForbidden, responseErrorBadRequest, responseErrorUnauthorize, responseErrorInternalServer} from '../actions/responseError'
- import {errorInfo} from '../actions/responseError'
- import {modalOpen} from '../actions/modal'
- import {BADREQUEST, UNAUTHORIZE, INTERNALSERVERERROR, FORBIDDEN} from '../actions/responseError'
- //redux-actionsを使っていることを前提としています
- function* responseInternalserver(){
- while(true){
- const action = yield take(responseErrorInternalServer);
- yield put(modalOpen({title: "eee"}));
- }
- }
- function* responseForbidden(){
- while(true){
- const action = yield take(responseErrorForbidden);
- yield put(modalOpen({title: "" }));
- }
- }
- function* responseUnauthorize(){
- while(true){
- const action = yield take(responseErrorUnauthorize);
- yield put(modalOpen({title: "fafaf"}));
- }
- }
- function* responseBadRequest(){
- while(true){
- const action = yield take(responseErrorBadRequest);
- yield put(modalOpen({title: "fafaf"}));
- }
- }
- function* errorInfoState(){
- while(true){
- const {payload, payload: {status, error}} = yield take(errorInfo);
- console.log(payload, "info")
- if(status === 402){
- const action = yield fork(responseBadRequest);
- yield put(responseErrorInternalServer())//responseErrorInternalServerが返すのはObjectでなければいけないと言われています。
- } else if (status === 401){
- yield put(responseErrorInternalServer(payload));//redux-actionsで作られたactoionCreatorは引数にpayloadを渡すことができます
- } else if (status=== 403){
- const action = yield put(responseForbidden);
- yield put(responseForbidden());
- } else {
- yield put(responseErrorInternalServer({payload}));
- }
- }
- }
- export default function* rootSaga(){
- yield all([
- fork(errorInfoState),
- fork(responseBadRequest),
- fork(responseUnauthorize),
- fork(responseForbidden),
- fork(responseInternalserver)
- ])
- }
Add Comment
Please, Sign In to add comment