Skip to content

Commit 93e4289

Browse files
committed
fix: Etc 예외를 비즈니스 예외로 통합하여 수정
1 parent e8a3810 commit 93e4289

File tree

6 files changed

+9
-34
lines changed

6 files changed

+9
-34
lines changed

src/main/java/eatda/exception/BusinessErrorCode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public enum BusinessErrorCode {
4949

5050
// image
5151
INVALID_IMAGE_TYPE("CLIENT010", "지원하지 않는 이미지 형식입니다.", HttpStatus.BAD_REQUEST),
52-
;
52+
FILE_UPLOAD_FAILED("SERVER002", "파일 업로드에 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR),
53+
FILE_URL_GENERATION_FAILED("SERVER003", "파일 URL 생성에 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR),
54+
PRESIGNED_URL_GENERATION_FAILED("SERVER004", "Presigned URL 생성에 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR);
5355

5456
private final String code;
5557
private final String message;

src/main/java/eatda/exception/EtcErrorCode.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public enum EtcErrorCode {
1616
NO_HEADER_FOUND("CLIENT008", "필수 헤더 값이 존재하지 않습니다.", HttpStatus.BAD_REQUEST),
1717
NO_PARAMETER_FOUND("CLIENT009", "필수 파라미터 값이 존재하지 않습니다.", HttpStatus.BAD_REQUEST),
1818

19-
INTERNAL_SERVER_ERROR("SERVER001", "서버 내부 에러가 발생했습니다.", HttpStatus.INTERNAL_SERVER_ERROR),
20-
FILE_UPLOAD_FAILED("SERVER002", "파일 업로드에 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR),
21-
FILE_URL_GENERATION_FAILED("SERVER003", "파일 URL 생성에 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR),
22-
PRESIGNED_URL_GENERATION_FAILED("SERVER004", "Presigned URL 생성에 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR);
19+
INTERNAL_SERVER_ERROR("SERVER001", "서버 내부 에러가 발생했습니다.", HttpStatus.INTERNAL_SERVER_ERROR);
2320

2421
private final String code;
2522
private final String message;

src/main/java/eatda/exception/GlobalExceptionHandler.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ public ResponseEntity<ErrorResponse> handleBusinessException(BusinessException e
8282
.body(response);
8383
}
8484

85-
@ExceptionHandler(S3ServiceException.class)
86-
public ResponseEntity<ErrorResponse> handleS3ServiceException(S3ServiceException exception) {
87-
return toErrorResponse(exception.getErrorCode());
88-
}
89-
9085
@ExceptionHandler(Exception.class)
9186
public ResponseEntity<ErrorResponse> handleException(Exception exception) {
9287
return toErrorResponse(EtcErrorCode.INTERNAL_SERVER_ERROR);

src/main/java/eatda/exception/S3ServiceException.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/eatda/service/common/ImageService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import eatda.exception.BusinessErrorCode;
44
import eatda.exception.BusinessException;
5-
import eatda.exception.EtcErrorCode;
6-
import eatda.exception.S3ServiceException;
75
import java.io.IOException;
86
import java.time.Duration;
97
import java.util.Set;
@@ -55,7 +53,7 @@ public String upload(MultipartFile file, String domain) {
5553
s3Client.putObject(request, RequestBody.fromInputStream(file.getInputStream(), file.getSize()));
5654
return key;
5755
} catch (IOException exception) {
58-
throw new S3ServiceException(EtcErrorCode.FILE_UPLOAD_FAILED, exception);
56+
throw new BusinessException(BusinessErrorCode.FILE_UPLOAD_FAILED);
5957
}
6058
}
6159

@@ -87,7 +85,7 @@ public String getPresignedUrl(String key) {
8785

8886
return s3Presigner.presignGetObject(presignRequest).url().toString();
8987
} catch (Exception exception) {
90-
throw new S3ServiceException(EtcErrorCode.PRESIGNED_URL_GENERATION_FAILED, exception);
88+
throw new BusinessException(BusinessErrorCode.PRESIGNED_URL_GENERATION_FAILED);
9189
}
9290
}
9391
}

src/test/java/eatda/service/common/ImageServiceTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010

1111
import eatda.exception.BusinessErrorCode;
1212
import eatda.exception.BusinessException;
13-
import eatda.exception.EtcErrorCode;
14-
import eatda.exception.S3ServiceException;
1513
import java.io.IOException;
1614
import java.net.URL;
1715
import java.time.Duration;
1816
import org.junit.jupiter.api.BeforeEach;
19-
import org.junit.jupiter.api.DisplayName;
2017
import org.junit.jupiter.api.Nested;
2118
import org.junit.jupiter.api.Test;
2219
import org.junit.jupiter.api.extension.ExtendWith;
@@ -119,17 +116,16 @@ class GeneratePresignedUrl {
119116
}
120117

121118
@Test
122-
@DisplayName("Presigner가 예외를 던지면 S3ServiceException으로 전환하여 던진다")
123-
void Presigner가_예외를_던지면_S3ServiceException으로_전환하여_던진다() {
119+
void Presigner가_예외를_던지면_BusinessException으로_전환하여_던진다() {
124120
String key = "stores/image.jpg";
125121

126122
when(s3Presigner.presignGetObject(any(GetObjectPresignRequest.class)))
127123
.thenThrow(SdkClientException.create("AWS SDK 통신 실패"));
128124

129-
S3ServiceException exception = assertThrows(S3ServiceException.class,
125+
BusinessException exception = assertThrows(BusinessException.class,
130126
() -> imageService.getPresignedUrl(key));
131127

132-
assertThat(exception.getErrorCode()).isEqualTo(EtcErrorCode.PRESIGNED_URL_GENERATION_FAILED);
128+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.PRESIGNED_URL_GENERATION_FAILED);
133129
}
134130
}
135131
}

0 commit comments

Comments
 (0)