mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-15 23:23:43 +08:00
调整项目目录
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.abin.frequencycontrol.exception;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum BusinessErrorEnum implements ErrorEnum {
|
||||
//==================================common==================================
|
||||
BUSINESS_ERROR(1001, "{0}"),
|
||||
//==================================user==================================
|
||||
//==================================chat==================================
|
||||
SYSTEM_ERROR(1001, "系统出小差了,请稍后再试哦~~"),
|
||||
CAPACITY_REFILL_ERROR(1001, "Capacity and refill rate must be positive"),
|
||||
|
||||
|
||||
;
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
@Override
|
||||
public Integer getErrorCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.abin.frequencycontrol.exception;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BusinessException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
protected Integer errorCode;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
protected String errorMsg;
|
||||
|
||||
public BusinessException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BusinessException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public BusinessException(Integer errorCode, String errorMsg) {
|
||||
super(errorMsg);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public BusinessException(Integer errorCode, String errorMsg, Throwable cause) {
|
||||
super(errorMsg, cause);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public BusinessException(ErrorEnum error) {
|
||||
super(error.getErrorMsg());
|
||||
this.errorCode = error.getErrorCode();
|
||||
this.errorMsg = error.getErrorMsg();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.abin.frequencycontrol.exception;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum CommonErrorEnum implements ErrorEnum {
|
||||
|
||||
SYSTEM_ERROR(-1, "系统出小差了,请稍后再试哦~~"),
|
||||
PARAM_VALID(-2, "参数校验失败{0}"),
|
||||
FREQUENCY_LIMIT(-3, "请求太频繁了,请稍后再试哦~~"),
|
||||
LOCK_LIMIT(-4, "请求太频繁了,请稍后再试哦~~"),
|
||||
;
|
||||
private final Integer code;
|
||||
private final String msg;
|
||||
|
||||
@Override
|
||||
public Integer getErrorCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.abin.frequencycontrol.exception;
|
||||
|
||||
public interface ErrorEnum {
|
||||
|
||||
Integer getErrorCode();
|
||||
|
||||
String getErrorMsg();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.abin.frequencycontrol.exception;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 自定义限流异常
|
||||
*/
|
||||
@Data
|
||||
public class FrequencyControlException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
protected Integer errorCode;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
protected String errorMsg;
|
||||
|
||||
public FrequencyControlException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public FrequencyControlException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public FrequencyControlException(ErrorEnum error) {
|
||||
super(error.getErrorMsg());
|
||||
this.errorCode = error.getErrorCode();
|
||||
this.errorMsg = error.getErrorMsg();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.abin.frequencycontrol.exception;
|
||||
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.abin.frequencycontrol.domain.vo.response.ApiResult;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Description: 业务校验异常码6
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum HttpErrorEnum implements ErrorEnum {
|
||||
ACCESS_DENIED(401, "登录失效,请重新登录"),
|
||||
;
|
||||
private Integer httpCode;
|
||||
private String msg;
|
||||
|
||||
@Override
|
||||
public Integer getErrorCode() {
|
||||
return httpCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void sendHttpError(HttpServletResponse response) throws IOException {
|
||||
response.setStatus(this.getErrorCode());
|
||||
ApiResult responseData = ApiResult.fail(this);
|
||||
response.setContentType(ContentType.JSON.toString(Charset.forName("UTF-8")));
|
||||
response.getWriter().write(JSONUtil.toJsonStr(responseData));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user