add some logs for testing

pull/1061/head
Ryan ZHAO 3 months ago
parent b0d397142b
commit 4303179b3f

@ -428,7 +428,10 @@ public enum PushNotificationAPI {
),
let notification: BencodeResponse<NotificationMetadata> = try? BencodeDecoder(using: dependencies)
.decode(BencodeResponse<NotificationMetadata>.self, from: decryptedData)
else { return (nil, .invalid, .failure) }
else {
SNLog("Failed to decrypt or decode notification")
return (nil, .invalid, .failure)
}
// If the metadata says that the message was too large then we should show the generic
// notification (this is a valid case)
@ -438,7 +441,10 @@ public enum PushNotificationAPI {
guard
let notificationData: Data = notification.data,
notification.info.dataLength == notificationData.count
else { return (nil, notification.info, .failureNoContent) }
else {
SNLog("Get notification data failed")
return (nil, notification.info, .failureNoContent)
}
// Success, we have the notification content
return (notificationData, notification.info, .success)

@ -15,13 +15,16 @@ extension BencodeResponse: Decodable {
info = try {
/// First try to decode it directly
if let info: T = try? container.decode(T.self) {
SNLog("Successfully decoded info directly")
return info
}
/// If that failed then we need to reset the container and try decode it as a JSON string
container = try decoder.unkeyedContainer()
let infoString: String = try container.decode(String.self)
SNLog("Successfully decoded info to JSON string")
let infoData: Data = try infoString.data(using: .ascii) ?? { throw NetworkError.parsingFailed }()
SNLog("Successfully decoded info to JSON data")
return try JSONDecoder(using: decoder.dependencies).decode(T.self, from: infoData)
}()

Loading…
Cancel
Save