Skip to content

Commit

Permalink
Merge pull request #48 from 7th-UMC/feature/45
Browse files Browse the repository at this point in the history
Feat : 사진 업로드 용량제한 설정, 예외처리
  • Loading branch information
hyeonda02 authored Aug 29, 2024
2 parents 913c21c + f5671bc commit 8de7250
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum ErrorStatus implements ErrorCode {
INVALID_CREDENTIALS(HttpStatus.NOT_FOUND, "USER4002", "유저의 비밀번호가 맞지 않습니다."),
//질문 관련 응답
QUESTION_NOT_FOUND(HttpStatus.NOT_FOUND, "QUESTION4001", "아이디에 해당하는 질문을 찾을 수 업습니다."),
ANSWER_NOT_FOUND(HttpStatus.NOT_FOUND, "ANSWER4001", "아이디에 해당하는 답변을 찾을 수 업습니다.");
ANSWER_NOT_FOUND(HttpStatus.NOT_FOUND, "ANSWER4001", "아이디에 해당하는 답변을 찾을 수 업습니다."),
_PAYLOAD_TOO_LARGE(HttpStatus.PAYLOAD_TOO_LARGE, "PAYLOAD4001","파일 크기가 허용된 최대 크기를 초과했습니다.");


private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import java.util.LinkedHashMap;
Expand Down Expand Up @@ -119,4 +120,16 @@ private ResponseEntity<Object> handleExceptionInternalConstraint(Exception e, Er
request
);
}

@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, @Nullable Object body, HttpHeaders headers,
HttpStatusCode status, WebRequest request) {
if (ex instanceof MaxUploadSizeExceededException) {
ErrorStatus errorStatus = ErrorStatus._PAYLOAD_TOO_LARGE;
ApiResponse<Object> customBody = ApiResponse.onFailure(errorStatus.getCode(), errorStatus.getMessage(), null);
return new ResponseEntity<>(customBody, headers, errorStatus.getHttpStatus());
}
return super.handleExceptionInternal(ex, body, headers, status, request);
}

}
5 changes: 5 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ spring:
allowed-headers: "*"
allow-credentials: true

servlet:
multipart:
max-file-size: 10MB
max-request-size: 20MB

cloud:
aws:
s3:
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ spring:
hbm2ddl:
auto: update

servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB

cloud:
aws:
s3:
Expand Down

0 comments on commit 8de7250

Please sign in to comment.