Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Refer to the table below regarding the different campaigns that can be implement
| `onSPUIFinished(callback: () => {})` | Called when the native SDKs is done removing the consent UI from the foreground. |
| `onFinished(callback: () => {})` | Called when all UI and network processes are finished. User consent is stored on the local storage of each platform (`UserDefaults` for iOS and `SharedPrefs` for Android). And it is safe to retrieve consent data with `getUserData` |
| `onMessageInactivityTimeout(callback: () => {})` | Called when the user becomes inactive while viewing a consent message. This allows your app to respond to user inactivity events. |
| `onError(callback: (description: string) => {})` | Called if something goes wrong. |
| `onError(callback: (error: SPError) => {})` | Called if something goes wrong. |

### Call `loadMessages`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.sourcepoint.cmplibrary.SpClient
import com.sourcepoint.cmplibrary.SpConsentLib
import com.sourcepoint.cmplibrary.exception.ConsentLibExceptionK
import com.sourcepoint.cmplibrary.creation.ConfigOption.SUPPORT_LEGACY_USPSTRING
import com.sourcepoint.cmplibrary.creation.SpConfigDataBuilder
import com.sourcepoint.cmplibrary.creation.makeConsentLib
Expand Down Expand Up @@ -179,7 +180,11 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
override fun onConsentReady(consent: SPConsents) {}

override fun onError(error: Throwable) {
emitInternalOnError(Json.encodeToString(mapOf("description" to error.message)))
val convertedError = error as? ConsentLibExceptionK
emitInternalOnError(Json.encodeToString(mapOf(
"spCode" to convertedError?.code as String,
"description" to convertedError?.message as String
)))
}

override fun onNoIntentActivitiesFound(url: String) {}
Expand Down
4 changes: 2 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export default function App() {
console.log("User inactive");
});

consentManager.current?.onError((description) => {
consentManager.current?.onError((error) => {
setSDKStatus(SDKStatus.Errored);
console.error(description);
console.error(error);
});

consentManager.current?.getUserData().then(setUserData);
Expand Down
27 changes: 25 additions & 2 deletions ios/RNSourcepointCmp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,36 @@ import React
}
}

@objcMembers public class RNError: NSObject {
public let code: String
public let errorDescription: String

@objc public init(code: String, description: String) {
self.code = code
self.errorDescription = description
}

func toDictionary() -> [String: Any] {
["spCode": code, "description": errorDescription]
}

@objc public func stringifiedJson() -> String {
if let jsonData = try? JSONSerialization.data(withJSONObject: toDictionary()),
let jsonString = String(data: jsonData, encoding: .utf8) {
return jsonString
} else {
return "{\"code\":\"unknown\"}"
}
}
}

@objc public protocol ReactNativeCmpImplDelegate {
func onAction(_ action: RNAction)
func onSPUIReady()
func onSPUIFinished()
func onFinished()
func onMessageInactivityTimeout()
func onError(description: String)
func onError(_ error: RNError)
}

@objcMembers public class ReactNativeCmpImpl: NSObject {
Expand Down Expand Up @@ -163,7 +186,7 @@ import React

public func onError(error: SPError) {
print("Something went wrong", error)
delegate?.onError(description: error.description)
delegate?.onError(RNError(code: error.spCode, description: error.description))
}

public func dismissMessage() {
Expand Down
7 changes: 2 additions & 5 deletions ios/ReactNativeCmp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ - (void)onAction:(RNAction*)action {
[self emitInternalOnAction: [action stringifiedJson]];
}

- (void)onErrorWithDescription:(NSString * _Nonnull)description {
NSDictionary *dict = @{@"description": description};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
[self emitInternalOnError: json];
- (void)onError:(RNError*)error {
[self emitInternalOnError: [error stringifiedJson]];
}

- (void)onFinished {
Expand Down
1 change: 1 addition & 0 deletions src/NativeReactNativeCmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export type SPBuildOptions = {
}

export type SPError = {
spCode: string;
description: string;
};

Expand Down
Loading