Skip to content

Commit

Permalink
error message display.
Browse files Browse the repository at this point in the history
  • Loading branch information
jchanvfx committed May 4, 2021
1 parent b39f086 commit cfc28da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
19 changes: 13 additions & 6 deletions LesmillsNZ WatchKit Extension/TimetableRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,27 @@ func createTimetableRequest(

// Handle the request.
guard let data = data else {
let errMessage = "\u{2297} \(error?.localizedDescription ?? "Unknown Error")"
callbackFunc([:], errMessage)
print(errMessage)
let err = "\u{2297} \(error?.localizedDescription ?? "Unknown Error")"
// error: run callback func.
print(err)
callbackFunc([:], err)
return
}

let responseJSON = try? JSONSerialization.jsonObject(with: data, options: [])
if let responseJSON = responseJSON as? [String: Any] {
guard let responseData = responseJSON["responseData"] as? [String:Any] else {
print("--- responseData key missing...!")
let err = "Error: \"responseData\" key missing...!"
// error: run callback func.
print(err)
callbackFunc([:], err)
return
}
guard let cards = responseData["cards"] as? [[String:Any]] else {
print("--- cards key missing...!")
let err = "Error: \"cards\" key missing...!"
// error: run callback func.
print(err)
callbackFunc([:], err)
return
}

Expand All @@ -62,7 +69,7 @@ func createTimetableRequest(
timetableData[fitnessClass.dateKey!, default: []].append(fitnessClass)
}
} catch {
print("FitnessClass mapping failed")
print("Error: FitnessClass mapping failed")
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion LesmillsNZ WatchKit Extension/Views/WeekListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ struct WeekListView: View {
Button(action: model.makeDataRequest) {
ReloadView()
}
// no data message.

// Error message display.
if (model.requestError != nil) {
Text(model.requestError!)
.foregroundColor(Color(hex:"#ed4e4e"))
.font(.system(size: 12))
.padding()
}

// No data message.
if (keyLabels.count == 0) {
Text("No timetable data avaliable please try reloading.")
.foregroundColor(Color.gray)
Expand Down
Binary file not shown.

0 comments on commit cfc28da

Please sign in to comment.