GlobalExceptionHandler.java 827 Bytes
package com.glsx.exception;

import com.glsx.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 全局异常处理
 * @author fengzhi
 * @version V1.0
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
   /**
     * 业务异常处理
     *
     * @param req
     * @param e
     * @return
     */
    @ExceptionHandler(value = BusinessException.class)
    public Result businessExceptionHandler(HttpServletRequest req, Exception e) {
        log.error("业务异常:" + e.getMessage());
        ApiException businessException = (ApiException) e;
        return businessException.getResultEntity();
    }
}