Merge branch 'master' of codeup.aliyun.com:64d9c5feeceb191898f636d7/honor-dd-light-ds-java
commit
2273150252
@ -0,0 +1,46 @@
|
||||
package com.ms.config;
|
||||
|
||||
import com.jinritemai.cloud.base.api.BaseResponse;
|
||||
import com.ms.api.common.R;
|
||||
import com.ms.api.common.Ret;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
* * @author admin
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
@ResponseBody
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
/**
|
||||
* 处理自定义的业务异常
|
||||
*/
|
||||
@ExceptionHandler(value = RuntimeException.class)
|
||||
public BaseResponse<Ret> bizExceptionHandler(RuntimeException e) {
|
||||
log.error("发生业务异常! msg: -> ", e);
|
||||
return R.ok(Ret.fail(e.getMessage()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理空指针的异常
|
||||
*/
|
||||
@ExceptionHandler(value = NullPointerException.class)
|
||||
public BaseResponse<Ret> exceptionHandler(NullPointerException e) {
|
||||
log.error("发生空指针异常! msg: -> ", e);
|
||||
return R.ok(Ret.fail(e.getMessage()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务器异常
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
public BaseResponse<Ret> exception(Exception e) {
|
||||
log.error("服务器异常! msg: -> ", e);
|
||||
return R.ok(Ret.fail(e.getMessage()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue