Skip to content

Commit b1da45a

Browse files
authored
Merge pull request #227 from TaskarCenterAtUW/fix-submission-apierror-handling
pass apierror instead of bool
2 parents 2cf5259 + 9044ca7 commit b1da45a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

GoInfoGame/GoInfoGame/Network/ApiManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class ApiManager {
196196
}
197197

198198
default:
199-
completion(.failure(APIError.custom("Unexpected HTTP status code: \(response.statusCode)")))
199+
completion(.failure(APIError(statusCode: response.statusCode)))
200200
}
201201
} else {
202202
completion(.failure(APIError.custom("No valid HTTP response received")))

GoInfoGame/GoInfoGame/data/DatasyncManager.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ class DatasyncManager {
1818
private var isSynching: Bool = false
1919

2020
private let dbInstance = DatabaseConnector.shared
21-
22-
func syncDataToOSM(completionHandler: @escaping (Bool) -> Void) {
21+
22+
func syncDataToOSM(completionHandler: @escaping (Result<Bool, APIError>) -> Void) {
2323
Task {
2424
do {
2525
let isSynced = try await syncData()
2626
print("Sync finished")
2727
if isSynced {
2828
print("Sync successful")
2929
DispatchQueue.main.async {
30-
completionHandler(true) // Success
30+
completionHandler(.success(true)) // Success
3131
}
3232
} else {
3333
print("Sync failed")
3434
DispatchQueue.main.async {
35-
completionHandler(false) // Failure
35+
completionHandler(.failure(APIError.custom("Sync failed. Please try again."))) // Failure
3636
}
3737
}
3838
} catch {
3939
print("Sync failed: \(error)")
4040
DispatchQueue.main.async {
41-
completionHandler(false) // Failure
41+
completionHandler(.failure(error as! APIError)) // Failure
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)