Skip to main content

Error Handling

In this document, errors are those caught with logic such as catch when a Promise is rejected during an API call.

Synchronization at the Moment of API Call Errors​

info

On the currently supported platforms, Android and iOS, errors occur under almost the same conditions.

For example, the Native Kakao SDK has a me function that fetches user information on Android and iOS.

The Kakao SDK uses callbacks internally (this package does not necessarily use ReactiveX).

Most API wrapper functions take the following form:

ios.swift
@objc public func me(
_ resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock
) {
onMain {
UserApi.shared.me { user, error in
if let error {
RNCKakaoUtil.reject(reject, error)
} else if let user {
resolve([
"id": user.id as Any
//...
])
} else {
RNCKakaoUtil.reject(reject, RNCKakaoError.responseNotFound(name: "user"))
}
}
}
}
android.kt
@ReactMethod
override fun me(promise: Promise) =
onMain {
UserApiClient.instance.me { user, error ->
if (error != null) {
promise.rejectWith(error)
} else if (user == null) {
promise.rejectWith(RNCKakaoResponseNotFoundException("user"))
} else {
promise.resolve(
argMap().apply {
putIntIfNotNull("id", user.id?.toInt())
// ...
},
)
}
}
}

Kakao SDK callbacks always use the same format: the first argument is the result, and the second is the error.

An error has occurred if the error argument is not null.

This package also checks whether the first argument contains a valid value.

note

This check is probably unnecessary (TILT).

If neither check finds a problem, the function returns the result.

Form of Errors​

Error objects passed to JavaScript's catch can vary slightly by platform.

The Native Kakao SDK uses platform-specific error codes, and this package passes the meaningful values through rather than unifying every error interface.

Most errors can be identified by code and typically have the following structure:

The package passes meaningful values through to make error handling easier.

  • Android
{
"message": "authentication tokens don't exist.",
"code": "TokenNotFound",
"nativeStackAndroid": [],
"userInfo": {
"isAppsFailed": false,
"isInvalidTokenError": false,
"isClientFailed": true,
"fatal": true,
"isAuthFailed": false,
"isApiFailed": false,
"nativeErrorMessage": "authentication tokens don't exist."
}
}
  • iOS
{
"code": "TokenNotFound",
"message": "authentication tokens not exist.",
"nativeStackIOS": [
"0 KakaoExample 0x000000010069dc9c RCTJSErrorFromCodeMessageAndNSError + 112",
"1 KakaoExample 0x00000001009a023c ___ZZN8facebook5react15ObjCTurboModule13createPromiseERNS_3jsi7RuntimeENSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEU13block_pointerFvU13block_pointerFvP11objc_objectEU13block_pointerFvP8NSStringSH_P7NSErrorEEENK3$_0clES4_RKNS2_5ValueEPSQ_m_block_invoke.59 + 388",
"2 KakaoExample 0x00000001002c5e20 $sSo8NSStringCSgACSo7NSErrorCSgIeyByyy_SSSgAGs5Error_pSgIegggg_TR + 380",
// ...
],
"domain": "RNCKakaoErrorDomain",
"userInfo": {
"isAuthFailed": false,
"isInvalidTokenError": false,
"isAppsFailed": false,
"isClientFailed": true,
"isApiFailed": false,
"fatal": false,
"nativeErrorMessage": "The operation couldn’t be completed. (KakaoSDKCommon.SdkError error 0.)"
}
}

The main fields are code and message; userInfo contains additional information.

Warning

code uses the Native Kakao SDK Enum case names directly, so it can differ if the platforms define different case names. The names are the same in most cases.

Example of Handling Errors​

Check the official Android and iOS API documentation for the available code values.

You can accurately distinguish and handle most errors as shown below:

 selectSingleFriend({ mode: 'popup', options: {} })
.then((res) => showMessage({ message: formatJson(res) }))
.catch((e) => {
if (e && typeof e is 'object') {
if (e.code === 'TokenNotFound') {
showMessage({ type: 'warning', message: 'Failed to retrieve token' });
} else {
// ...
}
} else {
showMessage({ type: 'warning', message: 'Unknown error' });
}
})

Package Error References​

Alongside Kakao Native SDK errors, react-native-kakao has its own error codes.

This package's error codes always start with Package-.

The package error codes are:

  • Package-Unknown: Any unclassified error, such as an unknown programming error, a failure to show Activity or ViewController, or a failure to open a URL. Check message for details.
  • Package-APIResponseNotFound: A Kakao Native SDK API callback returns no result even though there is no error.
  • Package-SDKNotInitialized: A Kakao API is called before the SDK has been initialized. Not all APIs return this error. APIs that could crash the app before initialization often check for this condition in advance.
  • Package-KakaoAppNotAvailable: An API that requires a Kakao app, such as KakaoTalk, fails because it cannot access that app. This includes cases where the Kakao app is installed but the service app lacks permission to open it.
  • Package-Assertion: An assertion in the package's JavaScript logic fails.

Android's ActivityNotFoundException​

Android APIs that require Context use getCurrentActivity() from the React Native Module.

Using ReactApplicationContext for actions that need theme information or additional flags, such as startActivity, can produce unexpected results.

The API therefore returns an error if getCurrentActivity() returns null.