update ExceptionHandlerAdvice

pull/26/head
3y 2 years ago
parent bc12554470
commit 3a719ef9a5

@ -32,6 +32,11 @@ public final class BasicResultVO<T> {
*/
private T data;
public BasicResultVO(String status, String msg) {
this.status = status;
this.msg = msg;
}
public BasicResultVO(RespStatusEnum status) {
this(status, null);
}

@ -49,7 +49,7 @@ public class ChannelAccountController {
@ApiOperation("/保存数据")
public ChannelAccount saveOrUpdate(@RequestBody ChannelAccount channelAccount) {
if (loginUtils.needLogin() && StrUtil.isBlank(channelAccount.getCreator())) {
throw new CommonException(RespStatusEnum.NO_LOGIN);
throw new CommonException(RespStatusEnum.NO_LOGIN.getCode(), RespStatusEnum.NO_LOGIN.getMsg());
}
channelAccount.setCreator(StrUtil.isBlank(channelAccount.getCreator()) ? AustinConstant.DEFAULT_CREATOR : channelAccount.getCreator());
@ -63,7 +63,7 @@ public class ChannelAccountController {
@ApiOperation("/根据渠道标识查询相关的记录")
public List<CommonAmisVo> query(Integer channelType, String creator) {
if (loginUtils.needLogin() && StrUtil.isBlank(creator)) {
throw new CommonException(RespStatusEnum.NO_LOGIN);
throw new CommonException(RespStatusEnum.NO_LOGIN.getCode(), RespStatusEnum.NO_LOGIN.getMsg());
}
creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : creator;
@ -78,7 +78,8 @@ public class ChannelAccountController {
@ApiOperation("/渠道账号列表信息")
public List<ChannelAccount> list(String creator) {
if (loginUtils.needLogin() && StrUtil.isBlank(creator)) {
throw new CommonException(RespStatusEnum.NO_LOGIN);
throw new CommonException(RespStatusEnum.NO_LOGIN.getCode(), RespStatusEnum.NO_LOGIN.getMsg());
}
creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : creator;

@ -74,7 +74,7 @@ public class MessageTemplateController {
@ApiOperation("/保存数据")
public MessageTemplate saveOrUpdate(@RequestBody MessageTemplate messageTemplate) {
if (loginUtils.needLogin() && StrUtil.isBlank(messageTemplate.getCreator())) {
throw new CommonException(RespStatusEnum.NO_LOGIN);
throw new CommonException(RespStatusEnum.NO_LOGIN.getCode(), RespStatusEnum.NO_LOGIN.getMsg());
}
return messageTemplateService.saveOrUpdate(messageTemplate);
}
@ -86,7 +86,7 @@ public class MessageTemplateController {
@ApiOperation("/列表页")
public MessageTemplateVo queryList(@Validated MessageTemplateParam messageTemplateParam) {
if (loginUtils.needLogin() && StrUtil.isBlank(messageTemplateParam.getCreator())) {
throw new CommonException(RespStatusEnum.NO_LOGIN);
throw new CommonException(RespStatusEnum.NO_LOGIN.getCode(), RespStatusEnum.NO_LOGIN.getMsg());
}
Page<MessageTemplate> messageTemplates = messageTemplateService.queryList(messageTemplateParam);
List<Map<String, Object>> result = Convert4Amis.flatListMap(messageTemplates.toList());
@ -160,8 +160,7 @@ public class MessageTemplateController {
@PostMapping("recall/{id}")
@ApiOperation("/撤回消息接口")
public SendResponse recall(@PathVariable("id") String id) {
SendRequest sendRequest = SendRequest.builder().code(BusinessCode.RECALL.getCode()).
messageTemplateId(Long.valueOf(id)).build();
SendRequest sendRequest = SendRequest.builder().code(BusinessCode.RECALL.getCode()).messageTemplateId(Long.valueOf(id)).build();
SendResponse response = recallService.recall(sendRequest);
if (!Objects.equals(response.getCode(), RespStatusEnum.SUCCESS.getCode())) {
throw new CommonException(response.getMsg());
@ -194,9 +193,7 @@ public class MessageTemplateController {
@PostMapping("upload")
@ApiOperation("/上传人群文件")
public HashMap<Object, Object> upload(@RequestParam("file") MultipartFile file) {
String filePath = dataPath +
IdUtil.fastSimpleUUID() +
file.getOriginalFilename();
String filePath = dataPath + IdUtil.fastSimpleUUID() + file.getOriginalFilename();
try {
File localFile = new File(filePath);
if (!localFile.exists()) {

@ -197,7 +197,7 @@ public class OfficialAccountController {
public WxMpUser checkLogin(String sceneId) {
String userInfo = redisTemplate.opsForValue().get(sceneId);
if (StrUtil.isBlank(userInfo)) {
throw new CommonException(RespStatusEnum.NO_LOGIN);
throw new CommonException(RespStatusEnum.SUCCESS.getCode(), RespStatusEnum.SUCCESS.getMsg(), RespStatusEnum.NO_LOGIN);
}
return JSON.parseObject(userInfo, WxMpUser.class);
}

@ -12,7 +12,7 @@ import lombok.Getter;
@Getter
public class CommonException extends RuntimeException {
private String code = RespStatusEnum.ERROR_400.getCode();
private RespStatusEnum respStatusEnum;
private RespStatusEnum respStatusEnum = null;
public CommonException(String message) {
super(message);
@ -29,6 +29,12 @@ public class CommonException extends RuntimeException {
this.code = code;
}
public CommonException(String code, String message, RespStatusEnum respStatusEnum) {
super(message);
this.code = code;
this.respStatusEnum = respStatusEnum;
}
public CommonException(String message, Exception e) {
super(message, e);
}

@ -37,7 +37,7 @@ public class ExceptionHandlerAdvice {
@ResponseStatus(HttpStatus.OK)
public BasicResultVO commonResponse(CommonException ce) {
log.error(Throwables.getStackTrace(ce));
return BasicResultVO.success(ce.getRespStatusEnum());
return new BasicResultVO(ce.getCode(), ce.getMessage(), ce.getRespStatusEnum());
}
}

Loading…
Cancel
Save