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 cn.axzo.framework.domain.web.code.RespCode;
import org.flowable.common.engine.api.FlowableOptimisticLockingException;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.springframework.stereotype.Component;

/**
 * 降级 FlowableOptimisticLockingException 异常，该异常在 Flowable 框架中是可以忽略的
 *
 * @author wangli
 * @see CommandContext#logException()
 * @since 2024/6/19 17:32
 */
@Component
public class FlowableOptimisticLockingExceptionHandlerAdvice extends AbstractExceptionApiResultHandler<FlowableOptimisticLockingException> {
    public FlowableOptimisticLockingExceptionHandlerAdvice(RespErrorCodeMappingProperties properties) {
        super(properties);
    }

    @Override
    protected IRespCode decode(FlowableOptimisticLockingException ex, IRespCode fallbackCode) {
        return new RespCode(BaseCode.SUCCESS.getCode(), ex.getMessage());
    }
}
