parent
3e47748c5a
commit
dd8da23c0f
@ -0,0 +1,22 @@
|
||||
package com.mashibing.api.advice;
|
||||
|
||||
import com.mashibing.api.util.R;
|
||||
import com.mashibing.api.vo.ResultVO;
|
||||
import com.mashibing.common.exception.ApiException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class ApiExceptionHandler{
|
||||
|
||||
@ExceptionHandler(ApiException.class)
|
||||
public ResultVO apiException(ApiException ex){
|
||||
return R.error(ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.mashibing.api.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 一些响应信息中code和msg的对应
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Getter
|
||||
public enum SmsCodeEnum {
|
||||
PARAMETER_ERROR(-10,"参数不合法!");
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
SmsCodeEnum(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.mashibing.common.constant;
|
||||
|
||||
/**
|
||||
* 缓存模块中的各种前缀
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public interface CacheConstant {
|
||||
|
||||
/**
|
||||
* 客户信息
|
||||
*/
|
||||
String CLIENT_BUSINESS = "client_business:";
|
||||
/**
|
||||
* 客户签名
|
||||
*/
|
||||
String CLIENT_SIGN = "client_sign:";
|
||||
/**
|
||||
* 客户签名的模板
|
||||
*/
|
||||
String CLIENT_TEMPLATE = "client_template:";
|
||||
/**
|
||||
* 客户的余额
|
||||
*/
|
||||
String CLIENT_BALANCE = "client_balance:";
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.mashibing.common.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Getter
|
||||
public enum ExceptionEnums {
|
||||
|
||||
ERROR_APIKEY(-1,"非法的apikey"),
|
||||
IP_NOT_WHITE(-2,"请求的ip不在白名单内"),
|
||||
ERROR_SIGN(-3,"无可用签名"),
|
||||
ERROR_TEMPLATE(-4,"无可用模板"),
|
||||
ERROR_MOBILE(-5,"手机号格式不正确"),
|
||||
BALANCE_NOT_ENOUGH(-6,"手客户余额不足"),
|
||||
PARAMETER_ERROR(-10,"参数不合法!"),
|
||||
;
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
ExceptionEnums(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.mashibing.common.exception;
|
||||
|
||||
import com.mashibing.common.enums.ExceptionEnums;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Getter
|
||||
public class ApiException extends RuntimeException {
|
||||
|
||||
private Integer code;
|
||||
|
||||
public ApiException(String message, Integer code) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
|
||||
public ApiException(ExceptionEnums enums) {
|
||||
super(enums.getMsg());
|
||||
this.code = enums.getCode();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue