package cn.axzo.workflow.server.advice;

import cn.axzo.framework.autoconfigure.web.exception.RespErrorCodeMappingProperties;
import cn.axzo.framework.autoconfigure.web.exception.handler.AbstractExceptionApiResultHandler;
import cn.axzo.framework.domain.web.code.BaseCode;
import cn.axzo.framework.domain.web.code.IRespCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException;

/**
 * 参数校验结果处理器,专门处理 @see BindException
 *
 * @author wangli
 * @since 2023/7/31 14:07
 */
@Component
@Slf4j
public class BindExceptionResultHandler extends AbstractExceptionApiResultHandler<BindException> {
    public BindExceptionResultHandler(RespErrorCodeMappingProperties properties) {
        super(properties);
    }

    @Override
    protected IRespCode decode(BindException ex, IRespCode fallbackCode) {
        return BaseCode.BAD_REQUEST;
    }

    @Override
    protected String getMessage(IRespCode respCode, BindException ex) {
        log.error("产生了 BindException 错误,请关注: {}", ex.getMessage());
        return super.getMessage(respCode, ex);
    }
}
