package com.project.zcustom.exception;

import com.project.zcustom.controller.core.AjaxResult;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description
 * @Author bqyang
 * @Date 2025/2/25 18:23
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MissingServletRequestParameterException.class)
    public AjaxResult handleMissingParams(MissingServletRequestParameterException ex) {
        String message = "请检查参数是否正确!";
        return AjaxResult.error(message);
    }

    @ExceptionHandler(ServiceException.class)
    public AjaxResult serviceException(ServiceException ex) {
        return AjaxResult.error(ex.getMessage());
    }

    @ExceptionHandler
    public AjaxResult handlerException(Exception e) {
        return AjaxResult.error(e.getMessage());
    }
}
