package com.bjtdba.api.handler;

import com.bjtdba.utils.ResponseUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public Object handler(Exception exception){

        if (exception instanceof Exception){
//            CustomException customException = (CustomException) exception;
            exception.printStackTrace();
            return ResponseUtil.fail(500, "请联系管理员");
        }else if(exception instanceof  NullPointerException){
            exception.printStackTrace();
            return ResponseUtil.fail(500, "请联系管理员");
        } else {
            return ResponseUtil.fail(120, "请联系管理员：" + exception.getMessage());
        }
    }
}
