Skip to content

Commit 13ed57e

Browse files
authored
fix: improve error handling in requestAuthorization (#75)
- Re-throw errors from requestAuthorization instead of silently catching them - Throw proper error for iOS < 16.0 instead of just logging - Remove console.error to allow proper error handling by callers This allows applications to properly handle authorization failures and provide appropriate user feedback.
1 parent 30e57ad commit 13ed57e

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/react-native-device-activity/ios/ReactNativeDeviceActivityModule.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,13 @@ public class ReactNativeDeviceActivityModule: Module {
547547
try await ac.requestAuthorization(
548548
for: forIndividualOrChild == "child" ? .child : .individual)
549549
} else {
550-
logger.log("⚠️ iOS 16.0 or later is required to request authorization.")
550+
let errorMessage = "iOS 16.0 or later is required to request authorization."
551+
logger.log("⚠️ \(errorMessage)")
552+
throw NSError(
553+
domain: "FamilyControls",
554+
code: 9999,
555+
userInfo: [NSLocalizedDescriptionKey: errorMessage]
556+
)
551557
}
552558
}
553559

packages/react-native-device-activity/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export async function requestAuthorization(
3939
forIndividualOrChild,
4040
);
4141
} catch (error) {
42-
// seems like we get a promise rejection if the user denies the authorization, but we can still request again
43-
console.error(error);
42+
// Re-throw the error so it can be properly handled by the caller
43+
throw error;
4444
}
4545
}
4646

0 commit comments

Comments
 (0)