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