글로벌 exception error.log 추가
This commit is contained in:
@@ -50,6 +50,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handleDuplicateFileException(
|
||||
DuplicateFileException e, HttpServletRequest request) {
|
||||
log.warn("[DuplicateFileException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
ApiResponseCode code = ApiResponseCode.CONFLICT;
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -68,6 +69,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handleValidationException(
|
||||
ValidationException e, HttpServletRequest request) {
|
||||
log.warn("[ValidationException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
ApiResponseCode code = ApiResponseCode.UNPROCESSABLE_ENTITY;
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -86,6 +88,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handleIllegalArgumentException(
|
||||
IllegalArgumentException e, HttpServletRequest request) {
|
||||
log.warn("[IllegalArgumentException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
ApiResponseCode code = ApiResponseCode.BAD_REQUEST;
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -104,6 +107,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerEntityNotFoundException(
|
||||
EntityNotFoundException e, HttpServletRequest request) {
|
||||
log.warn("[EntityNotFoundException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
String codeName = "NOT_FOUND_DATA";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -125,6 +129,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handleUnreadable(
|
||||
HttpMessageNotReadableException e, HttpServletRequest request) {
|
||||
log.warn("[HttpMessageNotReadableException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
String codeName = "BAD_REQUEST";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -146,6 +151,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerNoSuchElementException(
|
||||
NoSuchElementException e, HttpServletRequest request) {
|
||||
log.warn("[NoSuchElementException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
String codeName = "NOT_FOUND_DATA";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -167,6 +173,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerDataIntegrityViolationException(
|
||||
DataIntegrityViolationException e, HttpServletRequest request) {
|
||||
log.warn("[DataIntegrityViolationException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
String codeName = "DATA_INTEGRITY_ERROR";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -188,6 +195,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerMethodArgumentNotValidException(
|
||||
MethodArgumentNotValidException e, HttpServletRequest request) {
|
||||
log.warn("[MethodArgumentNotValidException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
String codeName = "BAD_REQUEST";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -209,6 +217,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerAccessDeniedException(
|
||||
AccessDeniedException e, HttpServletRequest request) {
|
||||
log.warn("[AccessDeniedException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
String codeName = "FORBIDDEN";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -230,6 +239,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerHttpServerErrorException(
|
||||
HttpServerErrorException e, HttpServletRequest request) {
|
||||
log.warn("[HttpServerErrorException] resource :{} ", e.getMessage());
|
||||
this.errorLog(request, e);
|
||||
String codeName = "BAD_GATEWAY";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -251,7 +261,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerIllegalStateException(
|
||||
IllegalStateException e, HttpServletRequest request) {
|
||||
log.warn("[IllegalStateException] resource :{} ", e.getMessage());
|
||||
|
||||
this.errorLog(request, e);
|
||||
String codeName = "UNPROCESSABLE_ENTITY";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -273,7 +283,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerDuplicateMemberException(
|
||||
MemberException.DuplicateMemberException e, HttpServletRequest request) {
|
||||
log.warn("[DuplicateMemberException] resource :{} ", e.getMessage());
|
||||
|
||||
this.errorLog(request, e);
|
||||
String codeName = "";
|
||||
|
||||
switch (e.getField()) {
|
||||
@@ -305,7 +315,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerMemberNotFoundException(
|
||||
MemberException.MemberNotFoundException e, HttpServletRequest request) {
|
||||
log.warn("[MemberNotFoundException] resource :{} ", e.getMessage());
|
||||
|
||||
this.errorLog(request, e);
|
||||
String codeName = "NOT_FOUND_USER";
|
||||
|
||||
ErrorLogEntity errorLog =
|
||||
@@ -328,7 +338,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerDuplicateKeyException(
|
||||
DuplicateKeyException e, HttpServletRequest request) {
|
||||
log.warn("[DuplicateKeyException] resource :{} ", e.getMessage());
|
||||
|
||||
this.errorLog(request, e);
|
||||
String codeName = "DUPLICATE_DATA";
|
||||
|
||||
ErrorLogEntity errorLog =
|
||||
@@ -350,7 +360,7 @@ public class GlobalExceptionHandler {
|
||||
public ResponseEntity<ApiResponseDto<String>> handleBadCredentials(
|
||||
BadCredentialsException e, HttpServletRequest request) {
|
||||
log.warn("[BadCredentialsException] resource : {} ", e.getMessage());
|
||||
|
||||
this.errorLog(request, e);
|
||||
String codeName = "UNAUTHORIZED";
|
||||
|
||||
ErrorLogEntity errorLog =
|
||||
@@ -377,7 +387,7 @@ public class GlobalExceptionHandler {
|
||||
public ApiResponseDto<String> handlerRuntimeException(
|
||||
RuntimeException e, HttpServletRequest request) {
|
||||
log.warn("[RuntimeException] resource :{} ", e.getMessage());
|
||||
|
||||
this.errorLog(request, e);
|
||||
String codeName = "INTERNAL_SERVER_ERROR";
|
||||
ErrorLogEntity errorLog =
|
||||
saveErrorLogData(
|
||||
@@ -397,8 +407,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ApiResponseDto<String> handlerException(Exception e, HttpServletRequest request) {
|
||||
log.error("[Exception] resource: {}, message: {}", request.getRequestURI(), e.getMessage());
|
||||
log.error("Exception stacktrace: ", e);
|
||||
this.errorLog(request, e);
|
||||
|
||||
String codeName = "INTERNAL_SERVER_ERROR";
|
||||
ErrorLogEntity errorLog =
|
||||
@@ -524,4 +533,15 @@ public class GlobalExceptionHandler {
|
||||
return ApiResponseDto.createException(
|
||||
code, code.getText(), HttpStatus.PAYLOAD_TOO_LARGE, errorLog.getId());
|
||||
}
|
||||
|
||||
private void errorLog(HttpServletRequest request, Throwable e) {
|
||||
String uri = request != null ? request.getRequestURI() : "N/A";
|
||||
|
||||
// 예외 타입명 (IllegalArgumentException, BadCredentialsException 등)
|
||||
String exceptionName = e.getClass().getSimpleName();
|
||||
|
||||
log.error("[{}] uri={}, message={}", exceptionName, uri, e.getMessage());
|
||||
|
||||
log.error("[{}] stacktrace", exceptionName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -29,8 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class MenuApiController {
|
||||
|
||||
private final MenuService menuService;
|
||||
|
||||
@Autowired private ObjectMapper objectMapper;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Operation(summary = "목록 조회", description = "모든 메뉴 조회")
|
||||
@ApiResponses(
|
||||
|
||||
Reference in New Issue
Block a user