Skip to content

Commit

Permalink
feat: (#97) GlobalExceptionHandler 로그 추가 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeomxon authored Jul 20, 2023
1 parent 179f202 commit 1c3200b
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package com.votogether.exception;

import lombok.extern.slf4j.Slf4j;
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 {

@ExceptionHandler
public ResponseEntity<ExceptionResponse> handleException(final Exception e) {
log.error("[" + e.getClass() + "] : " + e.getMessage());
return ResponseEntity.internalServerError()
.body(new ExceptionResponse(-9999, "알 수 없는 서버 에러가 발생했습니다."));
}

@ExceptionHandler
public ResponseEntity<ExceptionResponse> handleBadRequestException(final BadRequestException e) {
log.warn("[" + e.getClass() + "] : " + e.getMessage());
return ResponseEntity.badRequest()
.body(ExceptionResponse.from(e));
}

@ExceptionHandler
public ResponseEntity<ExceptionResponse> handleNotFoundException(final NotFoundException e) {
log.warn("[" + e.getClass() + "] : " + e.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(ExceptionResponse.from(e));
}
Expand Down

0 comments on commit 1c3200b

Please sign in to comment.