Skip to content

Instantly share code, notes, and snippets.

@just-a-stone
Last active June 11, 2021 03:05
Show Gist options
  • Save just-a-stone/a5989a6cdb2b89a4bd443d8c55aa72b7 to your computer and use it in GitHub Desktop.
Save just-a-stone/a5989a6cdb2b89a4bd443d8c55aa72b7 to your computer and use it in GitHub Desktop.
controller层 全局异常处理
package com.dycjr.xiakuan.workflow.support.interceptor;
import com.dycjr.xiakuan.basic.bean.RespDTO;
import com.dycjr.xiakuan.basic.exception.ErrorCode;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.FlowableException;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class ControllerAdvice {
/**
* 处理工作流异常
*
* @param request
* @param e
* @return
*/
@ExceptionHandler(FlowableException.class)
public RespDTO handleFlowableException(HttpServletRequest request, FlowableException e) {
log.error("流程引擎执行出错", e);
if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
// 自定义返回的异常 跳过
throw e;
}
return RespDTO.failed(ErrorCode.UNKNOWN_999999, e.getMessage());
}
/**
* 处理全局异常
*
* @param request
* @param e
* @return
*/
@ExceptionHandler(Throwable.class)
public RespDTO handleRoot(HttpServletRequest request, Throwable e) {
log.error("全局异常捕获", e);
return RespDTO.failed(ErrorCode.UNKNOWN_999999, e.getMessage());
}
}
public class Abc{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment