最近的一些修改 #7

Merged
xiaohai2271 merged 37 commits from dev into master 2020-08-01 21:26:46 +08:00
2 changed files with 10 additions and 8 deletions
Showing only changes of commit dcf44cefb6 - Show all commits

View File

@@ -39,8 +39,9 @@ public class ExceptionHandle {
public Response handle(Exception e) {
//自定义错误
if (e instanceof MyException) {
logger.debug("返回了自定义的exception,[code={},msg={}]", ((MyException) e).getCode(), e.getMessage());
return new Response(((MyException) e).getCode(), e.getMessage(), null);
MyException exception = (MyException) e;
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
}
//请求路径不支持该方法
if (e instanceof HttpRequestMethodNotSupportedException) {

View File

@@ -1,13 +1,16 @@
package cn.celess.blog.exception;
import cn.celess.blog.enmu.ResponseEnum;
import lombok.Data;
/**
* @author : xiaohai
* @date : 2019/03/28 16:56
*/
@Data
public class MyException extends RuntimeException {
private int code;
private Object result;
public MyException(int code, String msg) {
super(msg);
@@ -24,11 +27,9 @@ public class MyException extends RuntimeException {
this.code = e.getCode();
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
public MyException(ResponseEnum e, String msg, Object result) {
super(e.getMsg());
this.code = e.getCode();
this.result = result;
}
}