Add Logs in RestControllerAdvice

This commit is contained in:
MangKyu
2022-01-06 23:20:23 +09:00
parent 253e2ec57d
commit 0997ee5de9

View File

@@ -2,8 +2,9 @@ package com.mangkyu.employment.interview.app.common.erros.handler;
import com.mangkyu.employment.interview.app.common.erros.errorcode.CommonErrorCode;
import com.mangkyu.employment.interview.app.common.erros.errorcode.ErrorCode;
import com.mangkyu.employment.interview.app.common.erros.response.ErrorResponse;
import com.mangkyu.employment.interview.app.common.erros.exception.QuizException;
import com.mangkyu.employment.interview.app.common.erros.response.ErrorResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -18,6 +19,7 @@ import java.util.List;
import java.util.stream.Collectors;
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(QuizException.class)
@@ -28,6 +30,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<Object> handleIllegalArgument(final IllegalArgumentException e) {
log.warn("handleIllegalArgument", e);
final ErrorCode errorCode = CommonErrorCode.INVALID_PARAMETER;
return handleExceptionInternal(errorCode, e.getMessage());
}
@@ -38,7 +41,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
final HttpHeaders headers,
final HttpStatus status,
final WebRequest request) {
log.warn("handleIllegalArgument", e);
final ErrorCode errorCode = CommonErrorCode.INVALID_PARAMETER;
return handleExceptionInternal(e, errorCode);
}
@@ -51,6 +54,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler({Exception.class})
public ResponseEntity<Object> handleAllException(final Exception ex) {
log.warn("handleAllException", ex);
final ErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR;
return handleExceptionInternal(errorCode);
}