You've already forked FrameTour-BE
Init
This commit is contained in:
27
src/main/java/com/ycwl/basic/exception/AppException.java
Normal file
27
src/main/java/com/ycwl/basic/exception/AppException.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
import com.ycwl.basic.enums.AppStatesCodeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author songminsgong
|
||||
* @since 2022-11-23
|
||||
*/
|
||||
@Data
|
||||
public class AppException extends RuntimeException {
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
public AppException(Integer code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.msg = message;
|
||||
}
|
||||
|
||||
public AppException(AppStatesCodeEnum mobileCodeEnum) {
|
||||
super(mobileCodeEnum.getMessage());
|
||||
this.code = mobileCodeEnum.getCode();
|
||||
this.msg = mobileCodeEnum.getMessage();
|
||||
}
|
||||
}
|
38
src/main/java/com/ycwl/basic/exception/BaseException.java
Normal file
38
src/main/java/com/ycwl/basic/exception/BaseException.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author yangchen
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class BaseException extends RuntimeException {
|
||||
|
||||
private int status = 500;
|
||||
|
||||
public BaseException(String message, int status) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public BaseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public BaseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public BaseException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public BaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
27
src/main/java/com/ycwl/basic/exception/BizException.java
Normal file
27
src/main/java/com/ycwl/basic/exception/BizException.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
import com.ycwl.basic.enums.BizCodeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wenshijia
|
||||
* @date 2021年05月25日 22:41
|
||||
*/
|
||||
@Data
|
||||
public class BizException extends RuntimeException {
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
public BizException(Integer code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.msg = message;
|
||||
}
|
||||
|
||||
public BizException(BizCodeEnum bizCodeEnum) {
|
||||
super(bizCodeEnum.getMessage());
|
||||
this.code = bizCodeEnum.getCode();
|
||||
this.msg = bizCodeEnum.getMessage();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
|
||||
import com.ycwl.basic.utils.ApiConst;
|
||||
|
||||
public class CheckTokenException extends BaseException {
|
||||
|
||||
public CheckTokenException(String message) {
|
||||
// 5003
|
||||
super(message, ApiConst.Code.CODE_NO_SESSION.code());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
import com.ycwl.basic.enums.BizCodeEnum;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @date 2022年09月23日 10:19
|
||||
* 全局异常处理器
|
||||
*/
|
||||
@RestControllerAdvice(basePackages = {"com.ycwl.smartPark"})
|
||||
public class CustomExceptionHandle {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CustomExceptionHandle.class);
|
||||
|
||||
@ExceptionHandler(CheckTokenException.class)
|
||||
public ApiResponse tokenExceptionHandler(HttpServletResponse response, BaseException ex) {
|
||||
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
return ApiResponse.buildResponse(200, ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(MissTokenException.class)
|
||||
public ApiResponse tokenMissExceptionHandler(HttpServletResponse response, BaseException ex) {
|
||||
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
return ApiResponse.buildResponse(ex.getStatus(), ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(TokenExpireException.class)
|
||||
public ApiResponse tokenExpireException(HttpServletResponse response, BaseException ex) {
|
||||
response.setStatus(HttpStatus.OK.value());
|
||||
return ApiResponse.buildResponse(ex.getStatus(), ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(BaseException.class)
|
||||
public ApiResponse baseExceptionHandler(HttpServletResponse response, BaseException ex) {
|
||||
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
return ApiResponse.buildResponse(ex.getStatus(), ex.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义异常统一处理类
|
||||
*/
|
||||
@ExceptionHandler(value = BizException.class)
|
||||
public ApiResponse<String> handle(BizException bizException) {
|
||||
return ApiResponse.buildResponse(bizException.getCode(), bizException.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 异常统一返回处理
|
||||
*/
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public ApiResponse<String> handle(Exception e) {
|
||||
LOGGER.error("系统异常 -> {}", e.getMessage(), e);
|
||||
return ApiResponse.buildResult(BizCodeEnum.UNKNOWN_MISTAKE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动端自定义异常统一处理类
|
||||
*/
|
||||
@ExceptionHandler(value = AppException.class)
|
||||
public ApiResponse<String> handle(AppException appException) {
|
||||
return ApiResponse.buildResponse(appException.getCode(), appException.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动端自定义异常统一处理类
|
||||
*/
|
||||
@ExceptionHandler(value = HttpMessageNotReadableException.class)
|
||||
public ApiResponse<String> handle(HttpMessageNotReadableException httpMessageNotReadableException) {
|
||||
return ApiResponse.buildResponse(500, "请求参数格式错误");
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传超长异常统一处理
|
||||
*/
|
||||
@ExceptionHandler(value = SizeLimitExceededException.class)
|
||||
public ApiResponse<String> handle(SizeLimitExceededException sizeLimitExceededException) {
|
||||
return ApiResponse.buildResponse(415, "文件过大,请重新上传");
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
|
||||
import com.ycwl.basic.utils.ApiConst;
|
||||
|
||||
public class MissTokenException extends BaseException {
|
||||
|
||||
public MissTokenException(String message) {
|
||||
// 5003
|
||||
super(message, ApiConst.Code.CODE_MISS_TOKEN_ERROR.code());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
|
||||
import com.ycwl.basic.utils.ApiConst;
|
||||
|
||||
public class PermissionException extends BaseException{
|
||||
public PermissionException(String message) {
|
||||
// 5003
|
||||
super(message, ApiConst.Code.CODE_COMMON_ERROR.code());
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
|
||||
import com.ycwl.basic.utils.ApiConst;
|
||||
|
||||
public class RoleStatusException extends BaseException{
|
||||
public RoleStatusException(String message) {
|
||||
// 5003
|
||||
super(message, ApiConst.Code.CODE_COMMON_ERROR.code());
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.ycwl.basic.exception;
|
||||
|
||||
import com.ycwl.basic.utils.ApiConst;
|
||||
|
||||
/**
|
||||
* @author yangchen
|
||||
*/
|
||||
public class TokenExpireException extends BaseException {
|
||||
public TokenExpireException(String message) {
|
||||
// 5003
|
||||
super(message, ApiConst.Code.CODE_NO_SESSION.code());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user