package easydo.technology.config.exception;

import easydo.technology.exception.BizException;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/**
 * 处理Controller抛出的异常*
 * @author tianyf
 */
@RestControllerAdvice
@Log4j2
public class BizExceptionHandler {

    @ExceptionHandler({Exception.class})
    public Object handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
        log.error("业务处理异常======>" + request.getServletPath(), e);
        return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
    }
}
