Feature #5 申请友链时自动抓取网页信息 #6
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user