update ExceptionHandlerAdvice

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

@ -1,6 +1,7 @@
package com.java3y.austin.web.exception; package com.java3y.austin.web.exception;
import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.enums.RespStatusEnum;
import lombok.Getter;
/** /**
* @author kl * @author kl
@ -8,8 +9,10 @@ import com.java3y.austin.common.enums.RespStatusEnum;
* @description * @description
* @date 2023/2/9 19:00 * @date 2023/2/9 19:00
*/ */
@Getter
public class CommonException extends RuntimeException { public class CommonException extends RuntimeException {
private String code = RespStatusEnum.ERROR_400.getCode(); private String code = RespStatusEnum.ERROR_400.getCode();
private RespStatusEnum respStatusEnum;
public CommonException(String message) { public CommonException(String message) {
super(message); super(message);
@ -18,6 +21,7 @@ public class CommonException extends RuntimeException {
public CommonException(RespStatusEnum respStatusEnum) { public CommonException(RespStatusEnum respStatusEnum) {
super(respStatusEnum.getMsg()); super(respStatusEnum.getMsg());
this.code = respStatusEnum.getCode(); this.code = respStatusEnum.getCode();
this.respStatusEnum = respStatusEnum;
} }
public CommonException(String code, String message) { public CommonException(String code, String message) {
@ -34,7 +38,4 @@ public class CommonException extends RuntimeException {
this.code = code; this.code = code;
} }
public String getCode() {
return code;
}
} }

@ -36,9 +36,8 @@ public class ExceptionHandlerAdvice {
@ExceptionHandler({CommonException.class}) @ExceptionHandler({CommonException.class})
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public BasicResultVO commonResponse(CommonException ce) { public BasicResultVO commonResponse(CommonException ce) {
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_400, Throwables.getStackTrace(ce));
log.error(Throwables.getStackTrace(ce)); log.error(Throwables.getStackTrace(ce));
return result; return BasicResultVO.success(ce.getRespStatusEnum());
} }
} }

Loading…
Cancel
Save