|
@@ -2,8 +2,11 @@ package cn.org.spring.wechar.exception;
|
|
|
|
|
|
import cn.org.spring.wechar.bean.Result;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
-import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
|
|
/**
|
|
|
* @author: 谢辉
|
|
@@ -14,12 +17,21 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
* @version: 1.0
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-@RestControllerAdvice(basePackages = "cn.org.spring.wechar.**.controller")
|
|
|
+@ControllerAdvice(basePackages = "cn.org.spring.wechar")
|
|
|
public class ExceptionControllerAdvice {
|
|
|
|
|
|
- @ExceptionHandler(value = Throwable.class)
|
|
|
- public Result handleException(Throwable throwable) {
|
|
|
+ /**
|
|
|
+ * 响应json数据
|
|
|
+ *
|
|
|
+ * @param throwable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @ExceptionHandler(value = Exception.class)
|
|
|
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
+ public Result handleException(Exception throwable) {
|
|
|
log.error("错误异常{}", throwable);
|
|
|
return Result.fail("发生未知错误,稍后在试~");
|
|
|
}
|
|
|
+
|
|
|
}
|