package com.union.ai.api.aspect;


import com.union.ai.api.dto.Result;
import com.union.ai.api.enums.ErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindException;
import org.springframework.validation.ObjectError;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.UnsatisfiedServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.List;

@Slf4j
@ControllerAdvice(basePackages={"com.union.ai.api.controller"})  // 控制器增强
@ResponseBody
public class ExceptionAspect {


	@ExceptionHandler(value = {BindException.class, UnsatisfiedServletRequestParameterException.class, MissingServletRequestParameterException.class,MethodArgumentNotValidException.class})
	public String resolveException400(Exception e) {
		log.warn("参数异常", e);
		return new Result(ErrorEnum.ERROR_150000).toString();
	}


	@ExceptionHandler
	public String resolveException500(Exception e) {
		log.error("服务器异常", e);
		return new Result(ErrorEnum.ERROR_140000).toString();
	}
}