Commit b0a31abb by hulei

补充全局异常处理

parent 606992d2
package com.brilliance.isc.exception;
import com.brilliance.isc.vo.ResponseSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.sql.SQLException;
@RestControllerAdvice
public class ISCExceptionHandler {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
@ExceptionHandler(SQLException.class)
public ResponseSet handlerException(SQLException e) {
logger.error("",e);
return ResponseSet.fail("SQL执行异常!");
}
@ExceptionHandler(Exception.class)
public ResponseSet handlerException(Exception e) {
logger.error("",e);
return ResponseSet.fail("接口执行异常!["+e.getMessage()+"]");
}
@ExceptionHandler(Throwable.class)
public ResponseSet handlerException(Throwable e) {
logger.error("",e);
return ResponseSet.fail("接口内部异常!["+e.getMessage()+"]");
}
@ExceptionHandler (RestBizException.class)
public ResponseSet handlerException(RestBizException e) {
logger.error("",e);
return new ResponseSet(e.getCode(),e.getMessage());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment