Skip to content

Commit 0c549e7

Browse files
authored
Merge pull request #326 from KW-ClassLog/Fix/#324/s3-exception
🐛 Fix/ #324 s3 오류
2 parents c542c69 + e89f69b commit 0c549e7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

backend/src/main/java/org/example/backend/global/S3/exception/S3ErrorCode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
@Getter
1010
@AllArgsConstructor
1111
public enum S3ErrorCode implements BaseErrorCode {
12-
UPLOAD_FAIL(HttpStatus.BAD_REQUEST, "S3_404", "업로드 실패하였습니다.");
12+
UPLOAD_FAIL(HttpStatus.BAD_REQUEST, "S3_404", "업로드 실패하였습니다."),
13+
_S3_NOT_FOUND(HttpStatus.NOT_FOUND,"S3400","파일이 존재하지 않습니다")
14+
;
1315

1416

1517

backend/src/main/java/org/example/backend/global/S3/service/S3Service.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.amazonaws.services.s3.model.*;
66
import lombok.RequiredArgsConstructor;
77
import lombok.extern.slf4j.Slf4j;
8+
import org.example.backend.global.S3.exception.S3ErrorCode;
9+
import org.example.backend.global.S3.exception.S3Exception;
810
import org.springframework.beans.factory.annotation.Value;
911
import org.springframework.stereotype.Service;
1012
import org.springframework.web.multipart.MultipartFile;
@@ -53,6 +55,9 @@ public void deleteFile(String key) {
5355
* Presigned URL 발급 (다운로드용)
5456
*/
5557
public String getPresignedUrl(String key) {
58+
if(!amazonS3Client.doesObjectExist(bucket, key)) {
59+
throw new S3Exception(S3ErrorCode._S3_NOT_FOUND);
60+
}
5661
Date expiration = new Date(System.currentTimeMillis() + 1000 * 60 * 60); // 1시간
5762

5863
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, key)

0 commit comments

Comments
 (0)