异常打印

This commit is contained in:
wangw 2024-03-07 18:30:46 +08:00
parent ebbf0ba08d
commit e0291db00d
1 changed files with 9 additions and 3 deletions

View File

@ -1,8 +1,8 @@
package cn.ysk.cashier.config;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.utils.FastJsonUtils;
import cn.ysk.cashier.utils.SpringContextHolder;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
@ -40,7 +40,7 @@ public class AppApiMethodAspect {
@Around("pkg()")
// @SuppressWarnings("unchecked")
public Object around(ProceedingJoinPoint pjp) throws JsonProcessingException {
public Object around(ProceedingJoinPoint pjp) {
HttpServletRequest req = SpringContextHolder.getRequest();
Signature sign = pjp.getSignature();
MethodSignature ms = (MethodSignature) sign;
@ -61,6 +61,13 @@ public class AppApiMethodAspect {
FastJsonUtils.toJSONString(params),
FastJsonUtils.toJSONString(result)
);
return result;
} catch (BadRequestException e) {
log.error("\n>>>>>>{} {}\n>>>>>>{}\n>>>>>>Request: {}\n>>>>>>Exception: {}"
, req.getMethod(), req.getRequestURL(), req.getRemoteAddr(),
FastJsonUtils.toJSONString(params),
e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
} catch (Throwable e) {
if(StringUtils.isBlank(e.getMessage())){
log.error("\n>>>>>>{} {}\n>>>>>>{}\n>>>>>>Request: {}\n>>>>>>Exception: {}"
@ -76,6 +83,5 @@ public class AppApiMethodAspect {
ResponseEntity<String> body = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
return body;
}
return result;
}
}