Skip to content

Commit

Permalink
Optional logging for deep links methods (#120)
Browse files Browse the repository at this point in the history
* Fixed containerAlreadyPresenting error handing

* Add new parameter `shouldLogError`

* Make `DeeplinkWarningsError` to warning

---------

Co-authored-by: Almaz Ibragimov <[email protected]>
  • Loading branch information
timbaev and almazrafi authored May 29, 2024
1 parent 6c32215 commit 922b2bb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
42 changes: 33 additions & 9 deletions Sources/Deeplink/DeeplinkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -420,20 +420,27 @@ public final class DeeplinkManager: DeeplinkHandler {

/// Handle the URL by a suitable ``URLDeeplink`` and perform navigation, if possible.
///
/// This method does not raise an exception. Instead the error is logged through the navigator.
/// This method does not raise an exception. Instead the error is logged through the navigator if needed.
/// - Parameters:
/// - url: A URL Scheme or Universal Link from `UIApplicationDelegate` or `UIWindowSceneDelegate`.
///
/// - context: Additional context for checking and creating ``URLDeeplink``.
/// Must match the context type of ``URLDeeplink/URLContext``.
///
/// - shouldLogError: A Boolean flag indicating whether errors should be logged. The default value is `true`.
/// - Returns: `false` if there is no suitable ``URLDeeplink`` to handle the URL; otherwise `true`.
@discardableResult
public func handleURLIfPossible(_ url: URL, context: Any?) -> Bool {
public func handleURLIfPossible(
_ url: URL,
context: Any?,
shouldLogError: Bool = true
) -> Bool {
do {
return try handleURL(url, context: context)
} catch {
navigator.logError(error)
if shouldLogError {
navigator.logError(error)
}
}

return false
Expand Down Expand Up @@ -468,19 +475,28 @@ public final class DeeplinkManager: DeeplinkHandler {

/// Handle the Notification by a suitable ``NotificationDeeplink`` and perform navigation, if possible.
///
/// This method does not raise an exception. Instead the error is logged through the navigator.
/// This method does not raise an exception. Instead the error is logged through the navigator if needed.
/// - Parameters:
/// - response: The user’s response to an actionable notification.
///
/// - context: Additional context for checking and creating ``NotificationDeeplink``.
/// Must match the context type of ``NotificationDeeplink/NotificationContext``.
///
/// - shouldLogError: A Boolean flag indicating whether errors should be logged. The default value is `true`.
/// - Returns: `false` if there is no suitable ``NotificationDeeplink`` to handle the Notification;
/// otherwise `true`.
@discardableResult
public func handleNotificationIfPossible(response: UNNotificationResponse, context: Any?) -> Bool {
public func handleNotificationIfPossible(
response: UNNotificationResponse,
context: Any?,
shouldLogError: Bool = true
) -> Bool {
do {
return try handleNotification(response: response, context: context)
} catch {
navigator.logError(error)
if shouldLogError {
navigator.logError(error)
}
}

return false
Expand Down Expand Up @@ -516,22 +532,30 @@ public final class DeeplinkManager: DeeplinkHandler {

/// Handle the Notification by a suitable ``NotificationDeeplink`` and perform navigation, if possible.
///
/// This method does not raise an exception. Instead the error is logged through the navigator.
/// This method does not raise an exception. Instead the error is logged through the navigator if needed.
/// - Parameters:
/// - shortcut: An application shortcut item, also called a *Home screen dynamic quick action*,
/// that specifies a user-initiated action for your app.
///
/// - context: Additional context for checking and creating ``ShortcutDeeplink``.
/// Must match the context type of ``ShortcutDeeplink/ShortcutContext``.
///
/// - shouldLogError: A Boolean flag indicating whether errors should be logged. The default value is `true`.
///
/// - Returns: `false` if there is no suitable ``ShortcutDeeplink`` to handle the Shortcut App;
/// otherwise `true`.
@discardableResult
public func handleShortcutIfPossible(_ shortcut: UIApplicationShortcutItem, context: Any?) -> Bool {
public func handleShortcutIfPossible(
_ shortcut: UIApplicationShortcutItem,
context: Any?,
shouldLogError: Bool = true
) -> Bool {
do {
return try handleShortcut(shortcut, context: context)
} catch {
navigator.logError(error)
if shouldLogError {
navigator.logError(error)
}
}

return false
Expand Down
4 changes: 4 additions & 0 deletions Sources/Deeplink/Errors/DeeplinkWarningsError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ internal struct DeeplinkWarningsError: DeeplinkError {
"""
}

internal var isWarning: Bool {
true
}

internal let deeplinkType: Any.Type
internal let warnings: [Error]

Expand Down
6 changes: 5 additions & 1 deletion Sources/Screen/Actions/Modal/ScreenPresentAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public struct ScreenPresentAction<
}

container.present(presented, animated: animated) {
completion(.success(presented))
if container.presented === presented {
completion(.success(presented))
} else {
completion(.containerAlreadyPresenting(container, for: self))
}
}

if container.presented !== presented {
Expand Down

0 comments on commit 922b2bb

Please sign in to comment.