初始化车辆车型套餐服务
This commit is contained in:
85
src/main/java/com/sczx/car/exception/BizException.java
Normal file
85
src/main/java/com/sczx/car/exception/BizException.java
Normal file
@ -0,0 +1,85 @@
|
||||
package com.sczx.car.exception;
|
||||
|
||||
|
||||
import com.sczx.car.common.IApiCode;
|
||||
import com.sczx.car.common.enums.ApiErrorCode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangli
|
||||
*/
|
||||
public class BizException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
protected String errorCode;
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
protected String errorMsg;
|
||||
|
||||
public BizException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BizException(IApiCode apiCode) {
|
||||
super(apiCode.getCode());
|
||||
this.errorCode = apiCode.getCode();
|
||||
this.errorMsg = apiCode.getMsg();
|
||||
}
|
||||
|
||||
public BizException(IApiCode apiCode, Throwable cause) {
|
||||
super(apiCode.getCode(), cause);
|
||||
this.errorCode = apiCode.getCode();
|
||||
this.errorMsg = apiCode.getMsg();
|
||||
}
|
||||
|
||||
public BizException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
this.errorCode = ApiErrorCode.FAIL.getCode();
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public BizException(String errorCode, String errorMsg) {
|
||||
super(errorCode);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public BizException(String errorCode, String errorMsg, Throwable cause) {
|
||||
super(errorCode, cause);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(String errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.sczx.car.exception;
|
||||
|
||||
|
||||
import com.sczx.car.common.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
/**
|
||||
* @author zhangli
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
|
||||
/**
|
||||
* 处理自定义的业务异常
|
||||
*
|
||||
* @param req
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(value = BizException.class)
|
||||
@ResponseBody
|
||||
public Result bizExceptionHandler(HttpServletRequest req, BizException e) {
|
||||
log.warn("发生业务异常!原因是:{}", e.getErrorMsg(), e);
|
||||
return Result.fail(e.getErrorCode(), e.getErrorMsg());
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = InnerException.class)
|
||||
@ResponseBody
|
||||
public Result innerExceptionHandler(HttpServletRequest req, InnerException e) {
|
||||
log.error("发生服务内部异常!原因是:{}", e.getErrorMsg(), e);
|
||||
return Result.fail(e.getErrorCode(), e.getErrorMsg());
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Result exceptionHandler(HttpServletRequest req, Exception e) {
|
||||
log.error("意料外异常!原因是:{}", e.getMessage(), e);
|
||||
return Result.fail("99999", "系统内部异常");
|
||||
}
|
||||
|
||||
}
|
||||
86
src/main/java/com/sczx/car/exception/InnerException.java
Normal file
86
src/main/java/com/sczx/car/exception/InnerException.java
Normal file
@ -0,0 +1,86 @@
|
||||
package com.sczx.car.exception;
|
||||
|
||||
|
||||
import com.sczx.car.common.IApiCode;
|
||||
import com.sczx.car.common.enums.ApiErrorCode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangli
|
||||
|
||||
*/
|
||||
public class InnerException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
protected String errorCode;
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
protected String errorMsg;
|
||||
|
||||
public InnerException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InnerException(IApiCode apiCode) {
|
||||
super(apiCode.getCode());
|
||||
this.errorCode = apiCode.getCode();
|
||||
this.errorMsg = apiCode.getMsg();
|
||||
}
|
||||
|
||||
public InnerException(IApiCode apiCode, Throwable cause) {
|
||||
super(apiCode.getCode(), cause);
|
||||
this.errorCode = apiCode.getCode();
|
||||
this.errorMsg = apiCode.getMsg();
|
||||
}
|
||||
|
||||
public InnerException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
this.errorCode = ApiErrorCode.INNER_ERROR.getCode();
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public InnerException(String errorCode, String errorMsg) {
|
||||
super(errorCode);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public InnerException(String errorCode, String errorMsg, Throwable cause) {
|
||||
super(errorCode, cause);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(String errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user