Commit e0293f14 authored by 董建华's avatar 董建华

增加异常

parent e1b02636
......@@ -158,6 +158,12 @@ public class ExceptionHandlingController implements IBaseController {
public JsonResult handleDataException(DataException e) {
return JsonResult.buildErrorStateResult(e.getMessage(), null);
}
@ExceptionHandler({AppletException.class})
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public JsonResult handleAppletException(AppletException e) {
return JsonResult.buildErrorResultWhithCode(e.getMessage(), e.getCode());
}
@ExceptionHandler(BadSqlGrammarException.class)
@ResponseBody
......
package cn.quantgroup.xyqb.exception;
/**
* @author :dongjianhua
* @date :Created in 2020/9/17 14:43
* @description:小程序异常
* @modified By:
* @version: 1.0
*/
public class AppletException extends RuntimeException{
private String code;
public AppletException(String message) {
super(message);
}
public AppletException(String message,String code) {
super(message);
this.code = code;
}
public String getCode() {
return code;
}
}
......@@ -102,6 +102,13 @@ public class JsonResult<T> implements Serializable {
public static<T> JsonResult<T> buildFatalErrorStateResult(String msg, T data, Long businessCode) {
return new JsonResult(msg, ERROR_STATE_CODE, data, businessCode);
}
public static<T> JsonResult<T> buildErrorResultWhithCode(String msg, String businessCode) {
JsonResult jsonResult = new JsonResult();
jsonResult.setBusinessCode(businessCode);
jsonResult.setCode(String.format(Constants.ZERO_FILL_TEMPLATE, SUCCESS_CODE));
jsonResult.setMsg(msg);
return jsonResult;
}
/**
* 判断当前JsonResult是否是成功
......
......@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.controller.middleoffice.login.LoginVo;
import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.WechatUserInfo;
import cn.quantgroup.xyqb.exception.AppletException;
import cn.quantgroup.xyqb.exception.DataException;
import cn.quantgroup.xyqb.repository.IWeChatUserRepository;
import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService;
......@@ -84,14 +85,18 @@ public class AppletServiceImpl implements IAppletService {
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(openId, appName);
if (null == wechatUserInfo) {
log.error("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new DataException("未找到此用户");
throw new AppletException("未找到此用户","0401");
}
if (null == wechatUserInfo.getUserId()) {
log.error("用户未绑定到xyqb,appName:{} ,openId:{}", appName, openId);
throw new DataException("未找到此用户绑定信息");
throw new AppletException("未找到此用户绑定信息","0401");
}
User user = userService.findById(wechatUserInfo.getUserId());
User user = userService.findById(wechatUserInfo.getUserId());
if (null == user) {
log.error("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户","0401");
}
LoginVo loginVo = loginModule.loginByUserId(user.getRegisteredFrom(),
utmSource == null ? "" : utmSource, user.getId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment