package com.suntray.oa.app.common.exception;

import com.suntray.oa.app.common.response.BaseResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理器
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = {Exception.class})
    @ResponseBody
    public <T> BaseResponse<T> deal(Exception e) {
        BaseResponse<T> response = new BaseResponse<>();
        if (e instanceof BusinessException) {

        } else if (e instanceof ParamValidException) {

        } else {
            response.setCode(-1);
            response.setSuccess(false);
            response.setMessage("系统错误");
        }
        return response;
    }

}
