Bläddra i källkod

company-app Service异常捕获处理

Long 1 vecka sedan
förälder
incheckning
e1d63a5ca8

+ 13 - 0
fs-company-app/src/main/java/com/fs/app/exception/FSExceptionHandler.java

@@ -5,6 +5,7 @@ package com.fs.app.exception;
 
 import com.fs.common.core.domain.R;
 import com.fs.common.exception.CustomException;
+import com.fs.common.exception.ServiceException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.dao.DuplicateKeyException;
@@ -36,6 +37,18 @@ public class FSExceptionHandler {
 		return r;
 	}
 
+	/**
+	 * 处理自定义异常
+	 */
+	@ExceptionHandler(ServiceException.class)
+	public R handleRRException(ServiceException e){
+		R r = new R();
+		r.put("code", e.getCode());
+		r.put("msg", e.getMessage());
+
+		return r;
+	}
+
 	@ExceptionHandler(NoHandlerFoundException.class)
 	public R handlerNoFoundException(Exception e) {
 		logger.error(e.getMessage(), e);