-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from f-lab-edu/refactor/handle_error
- Loading branch information
Showing
6 changed files
with
72 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 20 additions & 4 deletions
24
RaiseMeUp/RaiseMeUp/Sources/Domain/UseCase/Program/Training.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
// | ||
// Tranining.swift | ||
// Training.swift | ||
// RaiseMeUp | ||
// | ||
// Created by 홍석현 on 11/28/23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Training: TrainingUseCase { | ||
public struct Training: TrainingUseCase { | ||
|
||
private let repository: TrainingRepositoryProtocol | ||
|
||
init(repository: TrainingRepositoryProtocol) { | ||
self.repository = repository | ||
} | ||
|
||
func getProgramList() async throws -> PullUpProgram { | ||
return try await repository.trainingProgram() | ||
public func getProgramList() async -> Result<PullUpProgram, TrainingError> { | ||
do { | ||
let program = try await repository.trainingProgram() | ||
guard !program.program.isEmpty else { return .failure(.emptyData) } | ||
|
||
return .success(program) | ||
} catch let error as NetworkError { | ||
switch error { | ||
case .invalidStatusCode, .notReachable, .timeOut: | ||
return .failure(.notConnected) | ||
case .noData: | ||
return .failure(.emptyData) | ||
case .unknown: | ||
return .failure(.unknown) | ||
} | ||
} catch { | ||
return .failure(.unknown) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters