You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-wms-java/src/main/java/com/glxp/api/handler/GlobalExceptionHandler.java

34 lines
1.0 KiB
Java

package com.glxp.api.handler;
import com.glxp.api.exception.JsonException;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 错误回调
*/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
// 拦截API异常
@ExceptionHandler(value = JsonException.class)
public BaseResponse handlerJsonException(JsonException e) {
// 返回对应的错误信息
return ResultVOUtils.error(e.getCode(), e.getMessage());
}
// 拦截API异常
@ExceptionHandler(value = RuntimeException.class)
public BaseResponse handlerRuntimeException(RuntimeException e) {
log.error(e.getMessage(), e);
// 返回对应的错误信息
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
}