package com.community.huiju.exception;

import com.community.commom.constant.Constant;
import com.community.commom.fushi.error.FuShiException;
import com.community.huiju.common.base.ResponseBean;
import com.community.huiju.enums.ResponseErrorsMessages;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 统一异常出口
 * @author weiximei
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class ExceptionHandleAdice {


    @ExceptionHandler(Exception.class)
    public ResponseBean handleException(Exception e){
        log.error(e.getMessage(),e);
        ResponseBean response = new ResponseBean();
        response.addError(ResponseErrorsMessages.SYSTEM_ERRORS.getCode(),ResponseErrorsMessages.SYSTEM_ERRORS.getMsg());
        return response;
    }


    @ExceptionHandler(WisdomException.class)
    public ResponseBean handleException(WisdomException e) {
        log.error(e.getMessage(),e);
        ResponseBean response = new ResponseBean();
        response.addError(e.getCode(),e.getMessage());
        return response;
    }

    @ExceptionHandler(FuShiException.class)
    public ResponseBean handleException(FuShiException e) {
        log.error(e.getMessage(),e);
        ResponseBean response = new ResponseBean();
        response.addError(e.getCode(),e.getMessage());
        return response;
    }


}
