Skip to content

Commit

Permalink
[BE] feat: 커스텀 예외 도입 및 GlobalExceptionHandler 처리 예외 수정 (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
J-I-H-O authored and takoyakimchi committed Oct 23, 2024
1 parent d6ca637 commit 3fa4555
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.woowacourse.friendogly;

import com.woowacourse.friendogly.exception.FriendoglyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<String> handle(RuntimeException exception) {
@ExceptionHandler(FriendoglyException.class)
public ResponseEntity<String> handle(FriendoglyException exception) {
return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<String> handle(MethodArgumentNotValidException exception) {
return new ResponseEntity<>("유효하지 않은 요청 값입니다.", HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<String> handle(HttpMessageNotReadableException exception) {
return new ResponseEntity<>("읽을 수 없는 HTTP 메세지입니다.", HttpStatus.BAD_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.woowacourse.friendogly.exception;

public class FriendoglyException extends RuntimeException {

public FriendoglyException(String message) {
super(message);
}
}

0 comments on commit 3fa4555

Please sign in to comment.