Authored by 邱骏

错误处理

@@ -269,7 +269,14 @@ const userController = { @@ -269,7 +269,14 @@ const userController = {
269 * @param res 269 * @param res
270 */ 270 */
271 wechatUserCallback(req, res, next) { 271 wechatUserCallback(req, res, next) {
272 - let wechatUserInfo = JSON.parse(req.query.wechatUserInfo); 272 + let wechatUserInfo;
  273 +
  274 + try {
  275 + wechatUserInfo = JSON.parse(req.query.wechatUserInfo);
  276 + } catch (err) {
  277 + wechatUserInfo = {};
  278 + }
  279 +
273 280
274 console.log('wechatUserCallBack:', wechatUserInfo); 281 console.log('wechatUserCallBack:', wechatUserInfo);
275 let user_name = '', 282 let user_name = '',
@@ -277,7 +284,7 @@ const userController = { @@ -277,7 +284,7 @@ const userController = {
277 union_id = ''; 284 union_id = '';
278 285
279 286
280 - if (wechatUserInfo) { 287 + if (wechatUserInfo && wechatUserInfo.nickname) {
281 user_name = wechatUserInfo.nickname; 288 user_name = wechatUserInfo.nickname;
282 head_img = wechatUserInfo.headimgurl; 289 head_img = wechatUserInfo.headimgurl;
283 union_id = wechatUserInfo.unionid || wechatUserInfo.openid; 290 union_id = wechatUserInfo.unionid || wechatUserInfo.openid;