Skip to main content

Errors

Every error the library gives you is a WatchError. This includes:

  • promise rejections from sendMessageData, startFileTransfer and updateApplicationContext
  • the error callback of sendMessage
  • the error field of activation-error, application-context-error, user-info-error and file-received-error events
  • the error field of a failed file transfer

WatchError​

WatchError extends Error and adds:

PropertyType
codeWatchErrorCodeA stable string, such as 'not-reachable'
nativeCodenumber | nullThe NSError code, such as 7007, when the error came from iOS
domainstring | nullThe NSError domain, such as 'WCErrorDomain', when the error came from iOS
namestringAlways 'WatchError'
messagestringThe system's description of the error

isWatchError​

isWatchError(value: unknown, code?: WatchErrorCode): value is WatchError

Returns true when value is a WatchError. Pass a code to also check the code.

import {isWatchError, updateApplicationContext} from 'react-native-watch-connectivity';

try {
await updateApplicationContext({token: 'abc'});
} catch (error) {
if (isWatchError(error, 'session-not-supported')) {
// no watch on this device
} else if (isWatchError(error)) {
console.warn(error.code, error.nativeCode);
} else {
throw error;
}
}

In a sendMessage error callback the argument is already a WatchError, so compare error.code directly:

import {sendMessage} from 'react-native-watch-connectivity';

sendMessage({ping: true}, undefined, error => {
if (error.code === 'not-reachable') {
// the watch app is not open
}
});

Error codes​

WatchErrorCode is a union of string literals. Each of Apple's WCErrorCode values has one. WATCH_ERROR_CODES lists them at runtime.

codeWCErrorCodeNative code
generic-errorgenericError7001
session-not-supportedsessionNotSupported7002
session-missing-delegatesessionMissingDelegate7003
session-not-activatedsessionNotActivated7004
device-not-paireddeviceNotPaired7005
watch-app-not-installedwatchAppNotInstalled7006
not-reachablenotReachable7007
invalid-parameterinvalidParameter7008
payload-too-largepayloadTooLarge7009
payload-unsupported-typespayloadUnsupportedTypes7010
message-reply-failedmessageReplyFailed7011
message-reply-timed-outmessageReplyTimedOut7012
file-access-deniedfileAccessDenied7013
delivery-faileddeliveryFailed7014
insufficient-spaceinsufficientSpace7015
session-inactivesessionInactive7016
transfer-timed-outtransferTimedOut7017
companion-app-not-installedcompanionAppNotInstalled7018
watch-only-appwatchOnlyApp7019
unknownAny other error, for example one from outside WCErrorDomain

On iPads, Android and the web, every send fails with session-not-supported.

ERROR_CODE_SESSION_UNREACHABLE (deprecated)​

ERROR_CODE_SESSION_UNREACHABLE equals 'not-reachable'. It is kept so that 2.x code still compiles. Compare error.code with 'not-reachable' instead.

import {ERROR_CODE_SESSION_UNREACHABLE} from 'react-native-watch-connectivity';

console.log(ERROR_CODE_SESSION_UNREACHABLE); // 'not-reachable'

In 2.x, an error's code was the bare native code, such as '7007', so it never equalled this constant.