中央热水项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.5 KiB

package com.mh.user.exception;
import com.mh.common.http.HttpResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice
public class GlobalException {
private static final Logger logger = LoggerFactory.getLogger(GlobalException.class);
/**
* 处理自定义异常
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler(value = ServiceRuntimeException.class)
public HttpResult serviceRuntimeException(ServiceRuntimeException e){
logger.error("发生业务异常!原因是:{}",e.getMessage());
return HttpResult.error(e.getCode(),e.getMessage());
}
/**
* 处理空指针异常
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler(value = NullPointerException.class)
public HttpResult exceptionHandler(NullPointerException e){
logger.error("发生空指针异常!原因是:",e);
return HttpResult.error(CommonNum.BODY_NOT_MATCH.getResultMsg());
}
/**
* 其它异常
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler(value = Exception.class)
public HttpResult exceptionHandler(Exception e){
logger.error("发生异常!原因是:",e);
return HttpResult.error(500,e.getMessage());
}
}