Skip to content

Commit

Permalink
chore: Detailed encoder errors (#4705)
Browse files Browse the repository at this point in the history
* Update @entur-private+abt-token-state-react-native-lib+2.1.6.patch

* Update @entur-private+abt-token-state-react-native-lib+2.1.6.patch
  • Loading branch information
jorelosorio committed Sep 9, 2024
1 parent 9fee0ee commit 4fcb47d
Showing 1 changed file with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@
diff --git a/node_modules/@entur-private/abt-token-state-react-native-lib/ios/TokenCoreModule.swift b/node_modules/@entur-private/abt-token-state-react-native-lib/ios/TokenCoreModule.swift
index a41752b..03e7b5d 100644
index a41752b..b558fda 100644
--- a/node_modules/@entur-private/abt-token-state-react-native-lib/ios/TokenCoreModule.swift
+++ b/node_modules/@entur-private/abt-token-state-react-native-lib/ios/TokenCoreModule.swift
@@ -443,7 +443,7 @@ public class TokenCoreModule: NSObject {
@@ -131,6 +131,39 @@ extension TokenCoreModuleError: IdentifiableError {
}
}

+extension TokenEncoderError: LocalizedError {
+ public var errorDescription: String? {
+ switch self {
+ case .errorUnableToGetClockTime:
+ return NSLocalizedString(
+ "Unable to get the current time",
+ comment: ""
+ )
+ case .errorSigning:
+ return NSLocalizedString(
+ "There was an error signing the token",
+ comment: ""
+ )
+ case .errorCreatingSecureContainer(let message):
+ let format = NSLocalizedString(
+ "There was an error creating the secure container: '%@'",
+ comment: ""
+ )
+
+ if let message = message {
+ return String(format: format, message)
+ }
+
+ return String(format: format, "unknown error")
+ case .errorInvalidSignaturePrivateKey:
+ return NSLocalizedString(
+ "Invalid signature private key",
+ comment: ""
+ )
+ }
+ }
+}
+

@objc(TokenCoreModule)
public class TokenCoreModule: NSObject {
@@ -442,8 +475,8 @@ public class TokenCoreModule: NSObject {
let tokenEncodingRequest = TokenEncodingRequest(deviceDetails: deviceDetailsProvider.deviceDetails, challenges: decodedChallenges, tokenActions: tokenPayloadActions, includeCertificate: includeCertificate)

token.encodeAsSecureContainer(tokenEncodingRequest: tokenEncodingRequest) { secureContainerWrapper, error in
if let error = error {
- if let error = error {
- return reject(self.mapErrorCode(error).code, "Error while generating the secure container", error)
+ return reject(self.mapErrorCode(error).code, "Error while generating the secure container: \(error.localizedDescription)", error)
+ if let error = error, let errorDescription = error.errorDescription {
+ return reject(self.mapErrorCode(error).code, errorDescription, error)
}

guard let base64EncodedSecureContainer = secureContainerWrapper?.base64EncodedString else {
@@ -597,8 +630,8 @@ public class TokenCoreModule: NSObject {
includeCertificate: includeCertificate
)
token.encodeAsSecureContainer(tokenEncodingRequest: tokenEncodingRequest) { [self] secureContainerWrapper, error in
- if let error = error {
- reject(self.mapErrorCode(error).code, "Error while generating the secure container", error)
+ if let error = error, let errorDescription = error.errorDescription {
+ reject(self.mapErrorCode(error).code, errorDescription, error)
}

if base64EncodedBarcode {

0 comments on commit 4fcb47d

Please sign in to comment.