update ExceptionHandlerAdvice

pull/26/head
3y 2 years ago
parent 6d70ab60c1
commit 64a37b8a3c

@ -36,7 +36,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.util.*;
/**
@ -196,16 +195,11 @@ public class OfficialAccountController {
@ApiOperation("/检查是否已经登录")
@AustinResult
public WxMpUser checkLogin(String sceneId) {
try {
String userInfo = redisTemplate.opsForValue().get(sceneId);
if (StrUtil.isBlank(userInfo)) {
throw new CommonException(RespStatusEnum.NO_LOGIN);
}
return JSON.parseObject(userInfo, (Type) WxMpUser.class);
} catch (Exception e) {
log.error("OfficialAccountController#checkLogin fail:{}", Throwables.getStackTraceAsString(e));
return null;
String userInfo = redisTemplate.opsForValue().get(sceneId);
if (StrUtil.isBlank(userInfo)) {
throw new CommonException(RespStatusEnum.NO_LOGIN);
}
return JSON.parseObject(userInfo, WxMpUser.class);
}
/**

@ -2,6 +2,7 @@ package com.java3y.austin.web.exception;
import com.java3y.austin.common.enums.RespStatusEnum;
import com.java3y.austin.common.vo.BasicResultVO;
import org.assertj.core.util.Throwables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
@ -10,16 +11,13 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* @author kl
* @version 1.0.0
* @description
* @date 2023/2/9 19:03
*/
@ControllerAdvice
@ControllerAdvice(basePackages = "com.java3y.austin.web.controller")
@ResponseBody
public class ExceptionHandlerAdvice {
private static final Logger log = LoggerFactory.getLogger(ExceptionHandlerAdvice.class);
@ -30,19 +28,16 @@ public class ExceptionHandlerAdvice {
@ExceptionHandler({Exception.class})
@ResponseStatus(HttpStatus.OK)
public BasicResultVO exceptionResponse(Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_500, "\r\n" + sw + "\r\n");
log.error(e.getMessage(), e);
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_500, "\r\n" + Throwables.getStackTrace(e) + "\r\n");
log.error(Throwables.getStackTrace(e));
return result;
}
@ExceptionHandler({CommonException.class})
@ResponseStatus(HttpStatus.OK)
public BasicResultVO commonResponse(CommonException ce) {
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_400, ce.getMessage());
log.error(ce.getMessage(), ce);
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_400, Throwables.getStackTrace(ce));
log.error(Throwables.getStackTrace(ce));
return result;
}
}

Loading…
Cancel
Save