Skip to content

Commit

Permalink
chore: Replace all hard-coded and nil error user info dictionaries wi…
Browse files Browse the repository at this point in the history
…th errorUserInfoDictionary helper (#839)

* Replace all hard-coded and nil error user info dictionaries with errorUserInfoDictionary helper

* Change error user info dict extension to be explicitly on optional dict to make CI happy

* Fix bad error catch

* Swiftlintery
  • Loading branch information
jnewc authored Apr 16, 2024
1 parent a0f8392 commit 8022506
Show file tree
Hide file tree
Showing 79 changed files with 575 additions and 2,062 deletions.
107 changes: 22 additions & 85 deletions Sources/PrimerSDK/Classes/Core/3DS/3DSService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {

guard let token = paymentMethodTokenData.token else {
let err = PrimerError.invalidClientToken(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: err)
throw err
Expand Down Expand Up @@ -118,10 +115,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
let err = PrimerError.invalidValue(
key: "resumeToken",
value: nil,
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: err)
completion(.failure(err))
Expand All @@ -142,10 +136,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {

} else {
let errContainer = Primer3DSErrorContainer.underlyingError(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString,
error: err)
continueInfo = ThreeDS.ContinueInfo(
Expand All @@ -156,10 +147,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {

guard let token = paymentMethodTokenData.token else {
let err = PrimerError.invalidClientToken(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: err)
completion(.failure(err.primerError))
Expand All @@ -180,10 +168,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {

#else
let missingSdkErr = Primer3DSErrorContainer.missingSdkDependency(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: missingSdkErr)

Expand All @@ -195,10 +180,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
.then { () -> Promise<ThreeDS.PostAuthResponse> in
guard let token = paymentMethodTokenData.token else {
let err = PrimerError.invalidClientToken(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: err)
throw err
Expand All @@ -222,10 +204,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
let uuid = UUID().uuidString

let err = PrimerError.invalidClientToken(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: uuid)

let internalErr = InternalError.failedToPerform3dsAndShouldBreak(error: err)
Expand All @@ -237,10 +216,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
let uuid = UUID().uuidString

let err = PrimerError.missingPrimerConfiguration(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: uuid)

let internalErr = InternalError.failedToPerform3dsAndShouldBreak(error: err)
Expand All @@ -257,10 +233,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
return Promise { seal in
guard let decodedJWTToken = PrimerAPIConfigurationModule.decodedJWTToken else {
let err = PrimerError.invalidClientToken(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)

let internalErr = InternalError.failedToPerform3dsAndShouldBreak(error: err)
Expand All @@ -269,10 +242,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
}

guard let apiConfiguration = AppState.current.apiConfiguration else {
let err = PrimerError.missingPrimerConfiguration(userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
let err = PrimerError.missingPrimerConfiguration(userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: err)
seal.reject(err)
Expand All @@ -283,10 +253,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
let uuid = UUID().uuidString

let err = Primer3DSErrorContainer.missing3DSConfiguration(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: uuid,
missingKey: "netceteraApiKey")

Expand Down Expand Up @@ -328,10 +295,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
if let primer3DSError = error as? Primer3DSError {
let err = Primer3DSErrorContainer.primer3DSSdkError(
paymentMethodType: paymentMethodType,
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: uuid,
initProtocolVersion: self.initProtocolVersion?.rawValue,
errorInfo: Primer3DSErrorInfo(
Expand All @@ -358,10 +322,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
let uuid = UUID().uuidString

let err = Primer3DSErrorContainer.invalid3DSSdkVersion(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: uuid,
invalidVersion: Primer3DS.version,
validVersion: "1.1.0")
Expand All @@ -376,10 +337,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
return Promise { seal in
guard let decodedJWTToken = PrimerAPIConfigurationModule.decodedJWTToken else {
let err = PrimerError.invalidClientToken(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)

let internalErr = InternalError.failedToPerform3dsAndShouldBreak(error: err)
Expand All @@ -406,10 +364,7 @@ class ThreeDSService: ThreeDSServiceProtocol, LogReporter {
if let primer3DSError = error as? Primer3DSError {
let err = Primer3DSErrorContainer.primer3DSSdkError(
paymentMethodType: paymentMethodType,
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: uuid,
initProtocolVersion: self.initProtocolVersion?.rawValue,
errorInfo: Primer3DSErrorInfo(
Expand Down Expand Up @@ -518,10 +473,7 @@ please set correct threeDsAppRequestorUrl in PrimerThreeDsOptions during SDK ini

let err = Primer3DSErrorContainer.primer3DSSdkError(
paymentMethodType: paymentMethodType,
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: uuid,
initProtocolVersion: self.initProtocolVersion?.rawValue,
errorInfo: Primer3DSErrorInfo(
Expand Down Expand Up @@ -572,10 +524,7 @@ please set correct threeDsAppRequestorUrl in PrimerThreeDsOptions during SDK ini
if let primer3DSError = err as? Primer3DSError {
let err = Primer3DSErrorContainer.primer3DSSdkError(
paymentMethodType: self?.paymentMethodType,
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString,
initProtocolVersion: self?.initProtocolVersion?.rawValue,
errorInfo: Primer3DSErrorInfo(
Expand All @@ -599,7 +548,7 @@ please set correct threeDsAppRequestorUrl in PrimerThreeDsOptions during SDK ini
let err = PrimerError.invalidValue(
key: "performChallenge.result",
value: nil,
userInfo: nil,
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
let internalErr = InternalError.failedToPerform3dsAndShouldBreak(error: err)
seal.reject(internalErr)
Expand All @@ -615,10 +564,7 @@ please set correct threeDsAppRequestorUrl in PrimerThreeDsOptions during SDK ini
) {
guard let decodedJWTToken = PrimerAPIConfigurationModule.decodedJWTToken else {
let err = PrimerError.invalidClientToken(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)

let internalErr = InternalError.failedToPerform3dsAndShouldBreak(error: err)
Expand All @@ -639,10 +585,7 @@ please set correct threeDsAppRequestorUrl in PrimerThreeDsOptions during SDK ini
} else {
primerErr = PrimerError.underlyingErrors(
errors: [underlyingErr],
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
}

Expand All @@ -665,10 +608,7 @@ please set correct threeDsAppRequestorUrl in PrimerThreeDsOptions during SDK ini
return Promise { seal in
guard let decodedJWTToken = PrimerAPIConfigurationModule.decodedJWTToken else {
let err = PrimerError.invalidClientToken(
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)

let internalErr = InternalError.failedToPerform3dsAndShouldBreak(error: err)
Expand All @@ -693,10 +633,7 @@ please set correct threeDsAppRequestorUrl in PrimerThreeDsOptions during SDK ini
} else {
primerErr = PrimerError.underlyingErrors(
errors: [underlyingErr],
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
}

Expand Down
5 changes: 1 addition & 4 deletions Sources/PrimerSDK/Classes/Core/3DS/Data Models/3DS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,7 @@ public class ThreeDS {
authentication = methodResponse
} else {
let err = InternalError.failedToDecode(message: "ThreeDS.BeginAuthResponse",
userInfo: ["file": #file,
"class": "\(Self.self)",
"function": #function,
"line": "\(#line)"],
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: err)
throw err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension Analytics {
} catch {
let err = PrimerError.underlyingErrors(
errors: [error],
userInfo: nil,
userInfo: .errorUserInfoDictionary(),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ would have been preferred (max BIN length exceeded).
let cardNumber = String(cardNumber.prefix(Self.maximumBinLength))

guard let decodedJWTToken = PrimerAPIConfigurationModule.decodedJWTToken else {
return rejectedPromise(withError: PrimerError.invalidClientToken(userInfo: nil, diagnosticsId: ""))
return rejectedPromise(withError: PrimerError.invalidClientToken(userInfo: .errorUserInfoDictionary(),
diagnosticsId: ""))
}

return Promise { resolver in
Expand Down
2 changes: 1 addition & 1 deletion Sources/PrimerSDK/Classes/Core/Logging/PrimerLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension PrimerLogger {
line: Int = #line,
function: String = #function) {
let metadata = PrimerLogMetadata(file: file, line: line, function: function)
logProxy(level: .debug, message: message, userInfo: nil, metadata: metadata)
logProxy(level: .debug, message: message, userInfo: userInfo, metadata: metadata)
}

public func info(message: String,
Expand Down
Loading

0 comments on commit 8022506

Please sign in to comment.