rest controller practice : exception log

This commit is contained in:
haerong22
2021-03-16 15:14:38 +09:00
parent 5afbec0fe4
commit d2574817a5
3 changed files with 512 additions and 1 deletions

View File

@@ -10,12 +10,14 @@ import com.example.restcontroller.user.exception.ExistsEmailException;
import com.example.restcontroller.user.exception.PasswordNotMatchException;
import com.example.restcontroller.user.exception.UserNotFoundException;
import com.example.restcontroller.user.model.ResponseMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
@@ -27,21 +29,25 @@ public class GlobalExceptionHandler {
BoardTypeNotFoundException.class,
BizException.class })
public ResponseEntity<?> badRequest(RuntimeException e) {
log.info(e.getClass().getName() + e.getMessage());
return ResponseResult.fail(e.getMessage());
}
@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<?> internalServerError(DataIntegrityViolationException e) {
log.info(e.getMessage());
return new ResponseEntity<>("회원 가입 실패", HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(AlreadyDeletedException.class)
public ResponseEntity<?> ok(AlreadyDeletedException e) {
log.info(e.getMessage());
return new ResponseEntity<>(e.getMessage(), HttpStatus.OK);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<?> exception(Exception e) {
log.info(e.getMessage());
return ResponseResult.fail(e.getMessage());
}
}

View File

@@ -36,4 +36,7 @@ spring:
logging:
level:
org.hibernate.SQL: trace
org.hibernate.type: trace
org.hibernate.type: trace
file:
name: ./logs/spring-jpa.log