Skip to content

Commit

Permalink
Merge pull request #66 from winebarrel/fix_PagerDutyModel_error
Browse files Browse the repository at this point in the history
Fix pager duty model error
  • Loading branch information
winebarrel authored Nov 5, 2024
2 parents eb59a74 + 15ff456 commit ab478af
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions PagerCall.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
CODE_SIGN_ENTITLEMENTS = PagerCall/PagerCall.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 97A8B2WE2P;
Expand Down Expand Up @@ -324,7 +324,7 @@
CODE_SIGN_ENTITLEMENTS = PagerCall/PagerCall.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 97A8B2WE2P;
Expand Down
6 changes: 3 additions & 3 deletions PagerCall/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import SwiftUI

struct ContentView: View {
@ObservedObject var pagerDuty: PagerDuty
@ObservedObject var pagerDuty: PagerDutyModel
@State private var hoverId = ""

var body: some View {
VStack {
if let pdErr = self.pagerDuty.error as? PagerDutyError {
if let pdErr = self.pagerDuty.error {
List {
HStack {
Spacer()
Expand Down Expand Up @@ -76,5 +76,5 @@ struct ContentView: View {
}

#Preview {
ContentView(pagerDuty: PagerDuty())
ContentView(pagerDuty: PagerDutyModel())
}
2 changes: 1 addition & 1 deletion PagerCall/PagerCallApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct PagerCallApp: App {
// NOTE: Define "apiKey" in PagerCallApp so that values are not lost during sleep.
@State private var apiKey = Vault.apiKey
@AppStorage("interval") private var interval = Constants.defaultInterval
@StateObject private var pagerDuty = PagerDuty()
@StateObject private var pagerDuty = PagerDutyModel()

// swiftlint:disable unused_declaration
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
Expand Down
4 changes: 0 additions & 4 deletions PagerCall/PagerDutyAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ struct PagerDutyAPI {
decoder.dateDecodingStrategy = .iso8601
let resp = try decoder.decode(IncidentsResp.self, from: data)

for iii in resp.incidents {
print(iii.createdAt.relative())
}

return resp.incidents
}

Expand Down
11 changes: 7 additions & 4 deletions PagerCall/PagerDutyModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ enum Status: String {
}

@MainActor
class PagerDuty: ObservableObject {
class PagerDutyModel: ObservableObject {
private let api = PagerDutyAPI()

@Published var incidents: Incidents = []
@Published var status: Status = .notOnCallWithoutIncident
@Published var updatedAt: Date?
@Published var error: Error?
@Published var error: PagerDutyError?

func update() async {
do {
Expand All @@ -40,8 +40,11 @@ class PagerDuty: ObservableObject {
}
} catch {
Logger.shared.error("failed to get incidents: \(error)")
status = .error
self.error = error

if let pdErr = error as? PagerDutyError {
status = .error
self.error = pdErr
}
}
}

Expand Down

0 comments on commit ab478af

Please sign in to comment.