@@ -13,11 +13,13 @@ public struct TokenizeResponse: Codable {
13
13
public let errors : [ PayrailsError ] ?
14
14
}
15
15
16
+
17
+
16
18
public struct PayrailsCSE {
17
19
var cseConfig : CSEConfiguration ?
18
20
19
- public init ( data: String , version: String ) {
20
- let config = parseConfig ( data: data)
21
+ public init ( data: String , version: String ) throws {
22
+ let config = try parseConfig ( data: data)
21
23
cseConfig = config
22
24
}
23
25
@@ -117,13 +119,27 @@ public struct PayrailsCSE {
117
119
task. resume ( )
118
120
}
119
121
120
- private func parseConfig( data: String ) -> CSEConfiguration {
122
+ private func parseConfig( data: String ) throws -> CSEConfiguration {
121
123
guard let decodedData = Data ( base64Encoded: data) else {
122
- fatalError ( " Failed to decode Base64 data " )
124
+ throw NSError (
125
+ domain: " payrails:client.cse " ,
126
+ code: 0 ,
127
+ userInfo: [
128
+ " code " : " payrails:client.cse:configuration.malformed " ,
129
+ " detail " : " The provided configuration string is invalid. Please ensure it matches the required format and structure as defined in the documentation " ,
130
+ " docUrl " : " https://docs.payrails.com/docs/sdk#initializing-the-sdk "
131
+ ] )
123
132
}
124
133
125
134
guard let config = try ? JSONDecoder ( ) . decode ( CSEConfiguration . self, from: decodedData) else {
126
- fatalError ( " Failed to parse CSEConfiguration " )
135
+ throw NSError (
136
+ domain: " payrails:client.cse " ,
137
+ code: 0 ,
138
+ userInfo: [
139
+ " code " : " payrails:client.cse:configuration.malformed " ,
140
+ " detail " : " The provided configuration string is invalid. Please ensure it matches the required format and structure as defined in the documentation " ,
141
+ " docUrl " : " https://docs.payrails.com/docs/sdk#initializing-the-sdk "
142
+ ] )
127
143
}
128
144
129
145
return config
@@ -146,7 +162,15 @@ public struct PayrailsCSE {
146
162
]
147
163
148
164
guard let publicKeyRef = SecKeyCreateWithData ( publicKeyData as CFData , options as CFDictionary , & error) else {
149
- fatalError ( " Failed to create public key: \( error!) " )
165
+ debugPrint ( " Failed to create public key: \( error!) " )
166
+ throw NSError (
167
+ domain: " payrails:client.cse " ,
168
+ code: 0 ,
169
+ userInfo: [
170
+ " code " : " payrails:client.cse:configuration.invalid " ,
171
+ " detail " : " The provided configuration is missing the public key required for encryption " ,
172
+ " docUrl " : " https://docs.payrails.com/docs/tokenize-cards-with-client-side-encryption " ,
173
+ ] )
150
174
}
151
175
152
176
return publicKeyRef
0 commit comments