Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat : 사진 업로드 용량제한 설정, 예외처리 #48

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading