Skip to content

Commit 9275383

Browse files
committed
♻️ [refactor] 에러 문구를 MyFitftyError타입으로 관리하게 개선
1 parent bd16a2b commit 9275383

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// MyFitftyError.swift
3+
// Core
4+
//
5+
// Created by 임영선 on 2023/02/23.
6+
// Copyright © 2023 Fitfty. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum MyFitftyError: Error {
12+
case noWeather
13+
case failUpload
14+
case failModify
15+
case failGetPost
16+
case others(String)
17+
}
18+
19+
extension MyFitftyError: LocalizedError {
20+
public var errorDescription: String? {
21+
switch self {
22+
case .noWeather:
23+
return NSLocalizedString("날씨를 불러오는데 실패했어요.\n해외 사진은 날씨 조회가 불가능해요.", comment: "noWeather")
24+
case .failUpload:
25+
return NSLocalizedString("핏프티 등록에 실패했어요. 잠시 후 다시 시도해 주세요.", comment: "failUpload")
26+
case .failModify:
27+
return NSLocalizedString("핏프티 수정에 실패했어요. 잠시 후 다시 시도해 주세요.", comment: "failModify")
28+
case .failGetPost:
29+
return NSLocalizedString("핏프티 정보를 가져오는데 실패했어요. 잠시 후 다시 시도해 주세요.", comment: "failGetPost")
30+
case .others(let message):
31+
return NSLocalizedString(message, comment: "Others Message")
32+
}
33+
}
34+
}

Fitfty/Projects/MainFeed/Sources/MyFitfty/ViewModel/MyFitfty/MyFitftyViewModel.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ extension MyFitftyViewModel: MyFitftyViewModelInput {
294294
currentState.send(.isLoading(false))
295295
} else {
296296
currentState.send(.isLoading(false))
297-
currentState.send(.errorMessage("프로필 조회에 알 수 없는 에러가 발생했습니다."))
297+
currentState.send(.errorMessage(MyFitftyError.failGetPost.localizedDescription))
298298
}
299299
} catch {
300-
Logger.debug(error: error, message: "작성했던 게시글 조회 실패")
300+
Logger.debug(error: error, message: MyFitftyError.failGetPost.localizedDescription)
301301
currentState.send(.isLoading(false))
302-
currentState.send(.errorMessage("작성했던 게시글 조회에 알 수 없는 에러가 발생했습니다."))
302+
currentState.send(.errorMessage(MyFitftyError.failGetPost.localizedDescription))
303303
}
304304
}
305305
}
@@ -431,7 +431,7 @@ private extension MyFitftyViewModel {
431431
], true))
432432
} catch {
433433
Logger.debug(error: error, message: "사진 날씨정보 가져오기 실패")
434-
self.currentState.send(.errorMessage("사진의 날씨 정보를 가져오는데 알 수 없는 에러가 발생했습니다."))
434+
self.currentState.send(.errorMessage(MyFitftyError.noWeather.localizedDescription))
435435
}
436436
}
437437
}
@@ -472,7 +472,7 @@ private extension MyFitftyViewModel {
472472
self.currentState.send(.completed(true))
473473
} else {
474474
self.currentState.send(.completed(false))
475-
self.currentState.send(.errorMessage("핏프티 등록에 알 수 없는 에러가 발생했습니다."))
475+
self.currentState.send(.errorMessage(MyFitftyError.failUpload.localizedDescription))
476476
}
477477

478478
case .modifyMyFitfty:
@@ -494,18 +494,18 @@ private extension MyFitftyViewModel {
494494
self.currentState.send(.completed(true))
495495
} else {
496496
self.currentState.send(.completed(false))
497-
self.currentState.send(.errorMessage("핏프티 수정에 알 수 없는 에러가 발생했습니다."))
497+
self.currentState.send(.errorMessage(MyFitftyError.failModify.localizedDescription))
498498
}
499499
}
500500
} else {
501501
self.currentState.send(.completed(false))
502-
self.currentState.send(.errorMessage("핏프티 등록에 알 수 없는 에러가 발생했습니다."))
502+
self.currentState.send(.errorMessage(MyFitftyError.failModify.localizedDescription))
503503
}
504504
self.currentState.send(.isLoading(false))
505505
} catch {
506-
Logger.debug(error: error, message: "핏프티 등록 실패")
506+
Logger.debug(error: error, message: MyFitftyError.failUpload.localizedDescription)
507507
self.currentState.send(.isLoading(false))
508-
self.currentState.send(.errorMessage("핏프티 등록에 알 수 없는 에러가 발생했습니다."))
508+
self.currentState.send(.errorMessage(MyFitftyError.failUpload.localizedDescription))
509509
}
510510
}
511511
}

0 commit comments

Comments
 (0)