package cn.axzo.workflow.server.controller.common;

import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.azxo.framework.common.model.CommonResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.ConstraintViolationException;

/**
 * 全局异常处理器
 *
 * @author wangli
 * @since 2023/7/10 17:10
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(WorkflowEngineException.class)
    @ResponseBody
    public CommonResponse<?> workflowEnginException(WorkflowEngineException exception) {
        return CommonResponse.error(exception.getMessage());
    }

    @ExceptionHandler(ConstraintViolationException.class)
    @ResponseBody
    public CommonResponse<?> constraintException(ConstraintViolationException exception) {
        return CommonResponse.error(exception.getMessage());
    }

}
