{"action":"created","issue":{"url":"https://api.github.com/repos/dvajs/dva/issues/141","repository_url":"https://api.github.com/repos/dvajs/dva","labels_url":"https://api.github.com/repos/dvajs/dva/issues/141/labels{/name}","comments_url":"https://api.github.com/repos/dvajs/dva/issues/141/comments","events_url":"https://api.github.com/repos/dvajs/dva/issues/141/events","html_url":"https://github.com/dvajs/dva/issues/141","id":181875935,"number":141,"title":"yield以及onError的问题","user":{"login":"bjwulin","id":8325711,"avatar_url":"https://avatars.githubusercontent.com/u/8325711?v=3","gravatar_id":"","url":"https://api.github.com/users/bjwulin","html_url":"https://github.com/bjwulin","followers_url":"https://api.github.com/users/bjwulin/followers","following_url":"https://api.github.com/users/bjwulin/following{/other_user}","gists_url":"https://api.github.com/users/bjwulin/gists{/gist_id}","starred_url":"https://api.github.com/users/bjwulin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjwulin/subscriptions","organizations_url":"https://api.github.com/users/bjwulin/orgs","repos_url":"https://api.github.com/users/bjwulin/repos","events_url":"https://api.github.com/users/bjwulin/events{/privacy}","received_events_url":"https://api.github.com/users/bjwulin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-09T09:05:19Z","updated_at":"2016-10-10T03:26:07Z","closed_at":null,"body":"1、我发现用if和else无法条件执行yield，比如：\r\n```\r\nif(data){\r\n   yield put({type: 'logined' , payload:data.data });\r\n}else{\r\n   yield put({type: 'toLogin'});\r\n}\r\n```\r\n断点调试的时候发现两个yield都执行了，我现在是合并到一条语句：\r\n`yield put({type: data ? 'logined' : 'toLogin', payload: data ? data.data : undefined});`\r\n总觉得写的难受，怎么写好一点？\r\n\r\n2、fetch的时候，很多情况下，我不需要处理异常，直接交给onError，但是有一部分请求，我是需要处理异常，因此我代码改成以下：\r\n```\r\nfunction request(url, options,throwError=true) {\r\n  return _fetch(fetch(url, options))\r\n    .then(checkStatus)\r\n    .then(parseJSON)\r\n    .then((data) =>{\r\n      const {status,message}=data;\r\n      if(status!==1){\r\n        const err = new Error(message,status);\r\n        throw err;\r\n      }\r\n      return {data};\r\n    }).catch((err) =>{\r\n      if(throwError){\r\n        throw err;\r\n      }else{\r\n        return {err};\r\n      }\r\n    });\r\n\r\n}\r\n```\r\n加入throwError的参数，来决定是抛异常，还是传递错误的err，不知道这种写法是否正常？\r\n"},"comment":{"url":"https://api.github.com/repos/dvajs/dva/issues/comments/252532843","html_url":"https://github.com/dvajs/dva/issues/141#issuecomment-252532843","issue_url":"https://api.github.com/repos/dvajs/dva/issues/141","id":252532843,"user":{"login":"sorrycc","id":35128,"avatar_url":"https://avatars.githubusercontent.com/u/35128?v=3","gravatar_id":"","url":"https://api.github.com/users/sorrycc","html_url":"https://github.com/sorrycc","followers_url":"https://api.github.com/users/sorrycc/followers","following_url":"https://api.github.com/users/sorrycc/following{/other_user}","gists_url":"https://api.github.com/users/sorrycc/gists{/gist_id}","starred_url":"https://api.github.com/users/sorrycc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sorrycc/subscriptions","organizations_url":"https://api.github.com/users/sorrycc/orgs","repos_url":"https://api.github.com/users/sorrycc/repos","events_url":"https://api.github.com/users/sorrycc/events{/privacy}","received_events_url":"https://api.github.com/users/sorrycc/received_events","type":"User","site_admin":false},"created_at":"2016-10-10T03:26:07Z","updated_at":"2016-10-10T03:26:07Z","body":"@Notedown-cn `yield call(error, ...args)` 会更标准点。"}}
{"actor":{"display_login":"sorrycc"}}