-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dev/refactor/jobpost/#64
- Loading branch information
Showing
32 changed files
with
696 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/com/prgrms2/java/bitta/global/advice/GlobalControllerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.prgrms2.java.bitta.global.advice; | ||
|
||
import jakarta.validation.ConstraintViolationException; | ||
import org.springframework.context.support.DefaultMessageSourceResolvable; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.multipart.MaxUploadSizeExceededException; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RestControllerAdvice | ||
public class GlobalControllerAdvice { | ||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
public ResponseEntity<?> handleArgsException(MethodArgumentNotValidException e) { | ||
List<String> reasons = e.getBindingResult() | ||
.getFieldErrors() | ||
.stream() | ||
.map(DefaultMessageSourceResolvable::getDefaultMessage) | ||
.toList(); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST) | ||
.body(Map.of("error", "잘못된 요청입니다.", "reason", reasons)); | ||
} | ||
|
||
@ExceptionHandler(ConstraintViolationException.class) | ||
public ResponseEntity<?> handleArgsException(ConstraintViolationException e) { | ||
return ResponseEntity.badRequest() | ||
.body(Map.of("error", "잘못된 요청입니다.", "reason", "ID는 음수가 될 수 없습니다.")); | ||
} | ||
|
||
@ExceptionHandler(MaxUploadSizeExceededException.class) | ||
public ResponseEntity<?> handleFileSizeLimitExceeded(MaxUploadSizeExceededException e) { | ||
return ResponseEntity.status(HttpStatus.PAYLOAD_TOO_LARGE) // Status 413 | ||
.body(Map.of("error", "Payload Too Large", "reason", "파일의 크기가 허용된 한도를 초과했습니다.")); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/prgrms2/java/bitta/global/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.prgrms2.java.bitta.global.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.multipart.MultipartResolver; | ||
import org.springframework.web.multipart.support.StandardServletMultipartResolver; | ||
|
||
@Configuration | ||
public class WebConfig { | ||
|
||
@Bean | ||
public MultipartResolver multipartResolver() { | ||
StandardServletMultipartResolver multipartResolver = new StandardServletMultipartResolver(); | ||
return multipartResolver; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.