diff --git a/Sources/PrivacyDashboard/WebsiteBreakage/WebsiteBreakage.swift b/Sources/PrivacyDashboard/WebsiteBreakage/WebsiteBreakage.swift index a8977054f..38976f63c 100644 --- a/Sources/PrivacyDashboard/WebsiteBreakage/WebsiteBreakage.swift +++ b/Sources/PrivacyDashboard/WebsiteBreakage/WebsiteBreakage.swift @@ -52,6 +52,8 @@ public struct WebsiteBreakage { let reportFlow: Source let protectionsState: Bool var lastSentDay: String? + let error: Error? + let httpStatusCode: Int? #if os(iOS) let siteType: SiteType // ?? not in documentation let atb: String @@ -73,7 +75,9 @@ public struct WebsiteBreakage { ampURL: String, urlParametersRemoved: Bool, protectionsState: Bool, - reportFlow: Source + reportFlow: Source, + error: Error?, + httpStatusCode: Int? ) { self.siteUrl = siteUrl self.category = category @@ -89,6 +93,8 @@ public struct WebsiteBreakage { self.protectionsState = protectionsState self.urlParametersRemoved = urlParametersRemoved self.reportFlow = reportFlow + self.error = error + self.httpStatusCode = httpStatusCode } #endif @@ -110,7 +116,9 @@ public struct WebsiteBreakage { reportFlow: Source, siteType: SiteType, atb: String, - model: String + model: String, + error: Error?, + httpStatusCode: Int? ) { self.siteUrl = siteUrl self.category = category @@ -129,12 +137,14 @@ public struct WebsiteBreakage { self.siteType = siteType self.atb = atb self.model = model + self.error = error + self.httpStatusCode = httpStatusCode } #endif /// A dictionary containing all the parameters needed from the Report Broken Site Pixel public var requestParameters: [String: String] { - var result = [ + var result: [String: String] = [ "siteUrl": siteUrl.trimmingQueryItemsAndFragment().absoluteString, "category": category, "description": description ?? "", @@ -155,6 +165,17 @@ public struct WebsiteBreakage { result["lastSentDay"] = lastSentDay } + if let httpStatusCode { + result["httpErrorCode"] = String(httpStatusCode) + } + + if let error = error as NSError? { + let errorDescription = "\(error.code) - \(error.localizedDescription)" + result["errorDescription"] = errorDescription + } else if let error { + result["errorDescription"] = error.localizedDescription + } + #if os(iOS) result["siteType"] = siteType.rawValue result["atb"] = atb diff --git a/Tests/PrivacyDashboardTests/WebsiteBreakageMoks.swift b/Tests/PrivacyDashboardTests/WebsiteBreakageMoks.swift index f4eedd248..6c5ec3fd2 100644 --- a/Tests/PrivacyDashboardTests/WebsiteBreakageMoks.swift +++ b/Tests/PrivacyDashboardTests/WebsiteBreakageMoks.swift @@ -35,7 +35,9 @@ struct WebsiteBreakageMoks { ampURL: "test", urlParametersRemoved: true, protectionsState: true, - reportFlow: .appMenu) + reportFlow: .appMenu, + error: nil, + httpStatusCode: nil) } static var testBreakage2: WebsiteBreakage { @@ -52,7 +54,9 @@ struct WebsiteBreakageMoks { ampURL: "test", urlParametersRemoved: true, protectionsState: true, - reportFlow: .appMenu) + reportFlow: .appMenu, + error: nil, + httpStatusCode: nil) } static var testBreakage3: WebsiteBreakage { @@ -69,6 +73,8 @@ struct WebsiteBreakageMoks { ampURL: "test", urlParametersRemoved: true, protectionsState: true, - reportFlow: .appMenu) + reportFlow: .appMenu, + error: nil, + httpStatusCode: nil) } }