fix: add generate exception global handler

This commit is contained in:
ReaJason
2025-08-13 23:53:40 +08:00
parent 5aae3c4dbe
commit 6a475983db
7 changed files with 40 additions and 17 deletions
@@ -1,5 +1,6 @@
package com.reajason.javaweb.boot.api;
import com.reajason.javaweb.GenerationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -22,10 +23,16 @@ public class GlobalExceptionHandler {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(GenerationException.class)
public ErrorResponse handleGenerationException(GenerationException exception) {
return new ErrorResponse(exception.getMessage());
}
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Throwable.class)
public ErrorResponse handleThrowable(Throwable throwable) {
log.error("请求出错", throwable);
log.error("Internal Exception", throwable);
return new ErrorResponse(throwable.getMessage());
}
}