package com.skyversation.poiaddr.config;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MissingServletRequestParameterException.class)
    @ResponseBody
    public Map<String, Object> handleMissingParams(MissingServletRequestParameterException ex) {
        Map<String, Object> result = new HashMap<>();
        result.put("status", 400);
        result.put("message", "请求缺少参数：" + ex.getParameterName());
        return result;
    }
}