-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make SDK Errors Public #1159
Make SDK Errors Public #1159
Changes from all commits
bb6e7bc
74e477d
d7091fa
621ed0a
207d084
34df364
dae293e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Foundation | ||
|
||
// Error codes associated with cards | ||
enum BTCardError: Error, CustomNSError, LocalizedError { | ||
public enum BTCardError: Error, CustomNSError, LocalizedError, Equatable { | ||
|
||
/// 0. Unknown error | ||
case unknown | ||
|
@@ -18,11 +18,11 @@ enum BTCardError: Error, CustomNSError, LocalizedError { | |
/// 4. Failed to fetch Braintree configuration | ||
case fetchConfigurationFailed | ||
|
||
static var errorDomain: String { | ||
public static var errorDomain: String { | ||
"com.braintreepayments.BTCardClientErrorDomain" | ||
} | ||
|
||
var errorCode: Int { | ||
public var errorCode: Int { | ||
switch self { | ||
case .unknown: | ||
return 0 | ||
|
@@ -37,7 +37,7 @@ enum BTCardError: Error, CustomNSError, LocalizedError { | |
} | ||
} | ||
|
||
var errorUserInfo: [String: Any] { | ||
public var errorUserInfo: [String: Any] { | ||
switch self { | ||
case .unknown: | ||
return [NSLocalizedDescriptionKey: "An unknown error occurred. Please contact support."] | ||
|
@@ -51,4 +51,10 @@ enum BTCardError: Error, CustomNSError, LocalizedError { | |
return [NSLocalizedDescriptionKey: "Failed to fetch Braintree configuration."] | ||
} | ||
} | ||
|
||
// MARK: - Equatable Conformance | ||
|
||
public static func == (lhs: BTCardError, rhs: BTCardError) -> Bool { | ||
lhs.errorCode == rhs.errorCode | ||
} | ||
Comment on lines
+55
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required for any of the enums with associated types. It it's able to resolve the equality of the error codes automatically. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import Foundation | ||
|
||
/// Error codes associated with a API Client. | ||
enum BTAnalyticsServiceError: Int, Error, CustomNSError, LocalizedError { | ||
public enum BTAnalyticsServiceError: Int, Error, CustomNSError, LocalizedError, Equatable { | ||
|
||
/// 0. Invalid API client | ||
case invalidAPIClient | ||
|
||
static var errorDomain: String { | ||
public static var errorDomain: String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do all the enum properties need to be public to resolve the merchant casting issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah - it needs to be public to satisfy protocol requirements since we are making the enum as a whole public. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need a taylor swift emoji for "swifty" things 😄 |
||
"com.braintreepayments.BTAnalyticsServiceErrorDomain" | ||
} | ||
|
||
var errorCode: Int { | ||
public var errorCode: Int { | ||
rawValue | ||
} | ||
|
||
var errorDescription: String? { | ||
public var errorDescription: String? { | ||
switch self { | ||
case .invalidAPIClient: | ||
return "API client must have client token or tokenization key" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🌟
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is slick! Much improved over forcing merchants to look at our markdown list of codes and hard code the int values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏈 Punt, but curious your thoughts.
For V7, we could get to something like this
if error == .canceled { ... }
if the error type we return is BT SDK specific. Is that what you're thinking as the V7 goal?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - I think that would be dope if we return strongly typed errors. The only case it could be a little weird is we would need to wrap any errors from core. I think in most cases we do that anyways but I know there are a few instances where we return a core error directly. Though I don't think it should be a blocker for strongly typed errors.