Guest User

Untitled

a guest
Feb 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. import {all, take, fork, put, call, join} from 'redux-saga/effects'
  2. import {responseErrorForbidden, responseErrorBadRequest, responseErrorUnauthorize, responseErrorInternalServer} from '../actions/responseError'
  3. import {errorInfo} from '../actions/responseError'
  4. import {modalOpen} from '../actions/modal'
  5. import {BADREQUEST, UNAUTHORIZE, INTERNALSERVERERROR, FORBIDDEN} from '../actions/responseError'
  6.  
  7. //redux-actionsを使っていることを前提としています
  8.  
  9. function* responseInternalserver(){
  10. while(true){
  11. const action = yield take(responseErrorInternalServer);
  12. yield put(modalOpen({title: "eee"}));
  13. }
  14. }
  15.  
  16. function* responseForbidden(){
  17. while(true){
  18. const action = yield take(responseErrorForbidden);
  19. yield put(modalOpen({title: "" }));
  20. }
  21. }
  22.  
  23. function* responseUnauthorize(){
  24. while(true){
  25. const action = yield take(responseErrorUnauthorize);
  26. yield put(modalOpen({title: "fafaf"}));
  27. }
  28. }
  29.  
  30. function* responseBadRequest(){
  31. while(true){
  32. const action = yield take(responseErrorBadRequest);
  33. yield put(modalOpen({title: "fafaf"}));
  34. }
  35. }
  36.  
  37. function* errorInfoState(){
  38. while(true){
  39. const {payload, payload: {status, error}} = yield take(errorInfo);
  40. console.log(payload, "info")
  41. if(status === 402){
  42. const action = yield fork(responseBadRequest);
  43. yield put(responseErrorInternalServer())//responseErrorInternalServerが返すのはObjectでなければいけないと言われています。
  44. } else if (status === 401){
  45. yield put(responseErrorInternalServer(payload));//redux-actionsで作られたactoionCreatorは引数にpayloadを渡すことができます
  46. } else if (status=== 403){
  47. const action = yield put(responseForbidden);
  48. yield put(responseForbidden());
  49. } else {
  50. yield put(responseErrorInternalServer({payload}));
  51. }
  52. }
  53. }
  54.  
  55. export default function* rootSaga(){
  56. yield all([
  57. fork(errorInfoState),
  58. fork(responseBadRequest),
  59. fork(responseUnauthorize),
  60. fork(responseForbidden),
  61. fork(responseInternalserver)
  62. ])
  63. }
Add Comment
Please, Sign In to add comment