package org.springblade.openapi.wps.exception;

import lombok.extern.slf4j.Slf4j;
import org.springblade.openapi.wps.pojo.enums.Api4WpsError;
import org.springblade.openapi.wps.pojo.vo.Api4WpsErrorVO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 *  wps 回调接口异常处理
 * @author bfhuange
 * @since 2024/11/26
 */
@Slf4j
@RestControllerAdvice
public class Api4WpsExceptionHandler {

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(Api4WpsException.class)
    public Api4WpsErrorVO handleException(Api4WpsException exception) {
        log.error("wps 回调接口异常：{}", exception.getMessage(), exception);
        Api4WpsError error = exception.getError();
        return new Api4WpsErrorVO(error.getCode(), error.getMessage(), exception.getMessage());
    }
}
