From 51c1845eb619064184861142469ee0ba397a8f97 Mon Sep 17 00:00:00 2001 From: Damith Amarasinghe Date: Tue, 21 Oct 2025 00:10:04 +0530 Subject: [PATCH] fix: improve error handling in requestAuthorization - 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. --- .../ios/ReactNativeDeviceActivityModule.swift | 8 +++++++- packages/react-native-device-activity/src/index.ts | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react-native-device-activity/ios/ReactNativeDeviceActivityModule.swift b/packages/react-native-device-activity/ios/ReactNativeDeviceActivityModule.swift index 655ce1b2..24d3eca3 100644 --- a/packages/react-native-device-activity/ios/ReactNativeDeviceActivityModule.swift +++ b/packages/react-native-device-activity/ios/ReactNativeDeviceActivityModule.swift @@ -547,7 +547,13 @@ public class ReactNativeDeviceActivityModule: Module { try await ac.requestAuthorization( for: forIndividualOrChild == "child" ? .child : .individual) } else { - logger.log("⚠️ iOS 16.0 or later is required to request authorization.") + let errorMessage = "iOS 16.0 or later is required to request authorization." + logger.log("⚠️ \(errorMessage)") + throw NSError( + domain: "FamilyControls", + code: 9999, + userInfo: [NSLocalizedDescriptionKey: errorMessage] + ) } } diff --git a/packages/react-native-device-activity/src/index.ts b/packages/react-native-device-activity/src/index.ts index 47f4ed4a..938f02da 100644 --- a/packages/react-native-device-activity/src/index.ts +++ b/packages/react-native-device-activity/src/index.ts @@ -39,8 +39,8 @@ export async function requestAuthorization( forIndividualOrChild, ); } catch (error) { - // seems like we get a promise rejection if the user denies the authorization, but we can still request again - console.error(error); + // Re-throw the error so it can be properly handled by the caller + throw error; } }