Skip to content

Commit f9af6fb

Browse files
committed
fix: add generate exception global handler
1 parent 8970f6a commit f9af6fb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

boot/src/main/java/com/reajason/javaweb/boot/api/GlobalExceptionHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.reajason.javaweb.boot.api;
22

3+
import com.reajason.javaweb.GenerationException;
34
import lombok.extern.slf4j.Slf4j;
45
import org.springframework.http.HttpStatus;
56
import org.springframework.http.ResponseEntity;
@@ -22,10 +23,16 @@ public ResponseEntity<?> handleNoResourceException() {
2223
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
2324
}
2425

26+
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
27+
@ExceptionHandler(GenerationException.class)
28+
public ErrorResponse handleGenerationException(GenerationException exception) {
29+
return new ErrorResponse(exception.getMessage());
30+
}
31+
2532
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
2633
@ExceptionHandler(Throwable.class)
2734
public ErrorResponse handleThrowable(Throwable throwable) {
28-
log.error("请求出错", throwable);
35+
log.error("Internal Exception", throwable);
2936
return new ErrorResponse(throwable.getMessage());
3037
}
3138
}

0 commit comments

Comments
 (0)