Skip to content

Commit

Permalink
✨ Add push preview error feedback toast
Browse files Browse the repository at this point in the history
  • Loading branch information
iujames committed Sep 17, 2024
1 parent f5b9a8e commit 6001714
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Examples/DeveloperCocoapodsExample/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Appcues (3.1.8)
- Appcues (3.1.9)
- AppcuesNotificationService (0.1.0)

DEPENDENCIES:
Expand All @@ -13,7 +13,7 @@ EXTERNAL SOURCES:
:path: "../../AppcuesNotificationService.podspec"

SPEC CHECKSUMS:
Appcues: e5c348611d6f77f075898b1eff6ca2a53e47d7b0
Appcues: 58ee609e4cff59090b20e8b251bc4ad2a5cc8cf0
AppcuesNotificationService: f7f11e9b156c50106b64b11f55eb0e02586198bd

PODFILE CHECKSUM: 24c643e3c9c013c74f5d561608aa37768cb0c43e
Expand Down
5 changes: 3 additions & 2 deletions Sources/AppcuesKit/Data/Networking/NetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,12 @@ internal class NetworkClient: Networking {
_ urlRequest: URLRequest,
completion: @escaping (_ result: Result<Void, Error>) -> Void
) {
let dataTask = config.urlSession.dataTask(with: urlRequest) { [weak self] _, response, error in
let dataTask = config.urlSession.dataTask(with: urlRequest) { [weak self] data, response, error in
let url = (response?.url ?? urlRequest.url)?.absoluteString ?? "<unknown>"
let statusCode = (response as? HTTPURLResponse)?.statusCode ?? -1
let logData = String(data: error?.data ?? data ?? Data.empty, encoding: .utf8) ?? ""

self?.config.logger.debug("RESPONSE: %{public}d %{public}@", statusCode, url)
self?.config.logger.debug("RESPONSE: %{public}d %{public}@\n%{private}@", statusCode, url, logData)

if let error = error {
completion(.failure(error))
Expand Down
25 changes: 22 additions & 3 deletions Sources/AppcuesKit/Presentation/DeepLinkHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internal class DeepLinkHandler: DeepLinkHandling {
published: false,
queryItems: queryItems,
trigger: .preview,
completion: previewCompletion
completion: experiencePreviewCompletion
)
case let .show(experienceID, queryItems):
container?.resolve(ContentLoading.self).load(
Expand All @@ -141,7 +141,7 @@ internal class DeepLinkHandler: DeepLinkHandling {
id: id,
published: false,
queryItems: queryItems,
completion: nil
completion: pushPreviewCompletion
)
case let .pushContent(id):
container?.resolve(ContentLoading.self).loadPush(
Expand All @@ -159,7 +159,7 @@ internal class DeepLinkHandler: DeepLinkHandling {
}
}

private func previewCompletion(_ result: Result<Void, Error>) {
private func experiencePreviewCompletion(_ result: Result<Void, Error>) {
guard case let .failure(error) = result else {
return
}
Expand All @@ -183,6 +183,25 @@ internal class DeepLinkHandler: DeepLinkHandling {
container?.resolve(UIDebugging.self).showToast(toast)
}

private func pushPreviewCompletion(_ result: Result<Void, Error>) {
guard case let .failure(error) = result else {
return
}

let message: String
switch error {
case NetworkingError.nonSuccessfulStatusCode(404):
message = "Push notification not found."
case is NetworkingError:
message = "Error loading push notification preview."
default:
message = "Push notification preview failed."
}

let toast = DebugToast(message: .custom(text: message), style: .failure)
container?.resolve(UIDebugging.self).showToast(toast)
}

@objc
private func sceneDidActivate() {
actionsToHandle.forEach(handle(action:))
Expand Down

0 comments on commit 6001714

Please sign in to comment.