package com.judong.chuanyiserver.exception;

import com.judong.chuanyiserver.enums.ResultEnum;
import com.judong.chuanyiserver.util.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 系统异常处理
     */
    @ExceptionHandler
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
    }

    /**
     * 自定义异常处理
     */
    @ExceptionHandler(value = CustomException.class)
    public Result handle(CustomException e) {
        e.printStackTrace();
        return Result.no(e.getCode(), e.getMessage());
    }
}
