Skip to content

Commit fe1eecf

Browse files
committed
refactor: 데이터가 없을 경우 빈 객체를 내리는 것으로 변경
1 parent 76bde6c commit fe1eecf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/com/programmers/springweekly/repository/voucher/MemoryVoucherRepository.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ public void update(Voucher voucher) {
3030

3131
@Override
3232
public Optional<Voucher> findById(UUID voucherId) {
33-
Voucher voucher = voucherMap.get(voucherId);
34-
35-
return Optional.ofNullable(voucher);
33+
try {
34+
Voucher voucher = voucherMap.get(voucherId);
35+
return Optional.of(voucher);
36+
} catch (NullPointerException e) {
37+
return Optional.empty();
38+
}
3639
}
3740

3841
@Override

0 commit comments

Comments
 (0)