Skip to content

Commit

Permalink
Merge pull request #19 from FC-Toy-Project-9/feature/global-exception
Browse files Browse the repository at this point in the history
Global Controller Advice 구현
  • Loading branch information
JeongUijeong authored Oct 27, 2023
2 parents 429a32d + 62c5fb5 commit 8f590ce
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.fc.toy_project2.global.exception;

import com.fc.toy_project2.global.DTO.ResponseDTO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalControllerAdvice {

@ExceptionHandler
public ResponseEntity<ResponseDTO<Void>> bindException(BindException e) {
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(ResponseDTO.res(HttpStatus.BAD_REQUEST,
e.getBindingResult().getAllErrors().get(0).getDefaultMessage()));
}
}

0 comments on commit 8f590ce

Please sign in to comment.