|
|
@@ -0,0 +1,36 @@
|
|
|
+package com.uas.platform.b2bManage.web;
|
|
|
+
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
+import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 定义异常返回,将后台抛出的异常信息返回到前台提示
|
|
|
+ *
|
|
|
+ * @author hejq
|
|
|
+ * @date 2018-08-02 22:21
|
|
|
+ */
|
|
|
+@ControllerAdvice
|
|
|
+@Component
|
|
|
+public class GlobalExceptionHandler {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 监控异常
|
|
|
+ *
|
|
|
+ * @param e 异常
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @ExceptionHandler(value = RuntimeException.class)
|
|
|
+ public ResponseEntity<String> defaultErrorHandler(Exception e) throws UnsupportedEncodingException {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Content-Type", "application/text; charset=utf-8");
|
|
|
+ return new ResponseEntity(e.getMessage(), headers, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+}
|