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());
    }



}
