Browse Source

Exception advice

wfansh 6 months ago
parent
commit
96ab52d352
1 changed files with 13 additions and 1 deletions
  1. 13 1
      src/main/java/com/wechi/adweb/bridge/exception/ExceptionAdvice.java

+ 13 - 1
src/main/java/com/wechi/adweb/bridge/exception/ExceptionAdvice.java

@@ -30,7 +30,6 @@ public class ExceptionAdvice {
     @ExceptionHandler({BadRequestException.class})
     public OpenAPIResponse<?> handleBadRequestException(BadRequestException e) {
         log.error(Objects.toString(e.getApiRequest()), e);
-
         return OpenAPIResponse.<List<? extends GAReportDataDTO>>builder()
                 .status(APIStatus.BAD_REQUEST)
                 .message("Invalid request parameters")
@@ -45,7 +44,20 @@ public class ExceptionAdvice {
     @ExceptionHandler({DataException.class})
     public OpenAPIResponse<?> handleDataException(DataException e) {
         log.error(e.getMessage(), e);
+        return OpenAPIResponse.builder()
+                .status(APIStatus.INTERNAL_SERVER_ERROR)
+                .message(e.getMessage())
+                .build();
+    }
 
+    /**
+     * @return 500 INTERNAL_SERVER_ERROR
+     */
+    @ResponseBody
+    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+    @ExceptionHandler({Exception.class, RuntimeException.class})
+    public OpenAPIResponse<?> handleException(Exception e) {
+        log.error(e.getMessage(), e);
         return OpenAPIResponse.builder()
                 .status(APIStatus.INTERNAL_SERVER_ERROR)
                 .message(e.getMessage())