StdInterfaceExceptionHandler.java
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cn.com.glsx.stdinterface.common.exception;
import com.glsx.plat.core.web.R;
import com.glsx.plat.exception.ExceptionLevel;
import com.glsx.plat.exception.GlobalExceptionHandler;
import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.BindingException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 全局异常处理
*
* @author payu
*/
@Slf4j
@RestControllerAdvice
public class StdInterfaceExceptionHandler extends GlobalExceptionHandler {
@ExceptionHandler(StdInterfaceException.class)
public R handleAdminException(StdInterfaceException e) {
return R.error(e.getErrorCode(), e.getMessage());
}
/**
* 引入Feign服务的话
*
* @param e
* @return
*/
@ExceptionHandler(FeignException.class)
public R handleFeignException(FeignException e) {
return R.error(e.status(), e.getMessage());
}
/**
* Mybatis BindingException
*
* @param e
* @return
*/
@ExceptionHandler(BindingException.class)
public R handleBindingException(BindingException e) {
return R.error(e.getMessage());
}
@Override
protected void saveException(Exception e, ExceptionLevel level) {
super.saveException(e, level);
}
}