Skip to content
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

Paywalls: improve error display #3577

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
8 changes: 6 additions & 2 deletions RevenueCatUI/Data/LocalizedAlertError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ struct LocalizedAlertError: LocalizedError {
}

var errorDescription: String? {
return "\(self.underlyingError.domain) \(self.underlyingError.code)"
if self.underlyingError is ErrorCode {
return "Error"
} else {
return "\(self.underlyingError.domain) \(self.underlyingError.code)"
}
}

var failureReason: String? {
if let errorCode = self.underlyingError as? ErrorCode {
return errorCode.description
return "Error \(self.underlyingError.code): \(errorCode.description)"
} else {
return self.underlyingError.localizedDescription
}
Expand Down
44 changes: 44 additions & 0 deletions Tests/RevenueCatUITests/Data/LocalizedAlertErrorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// LocalizedAlertErrorTests.swift
//
//
// Created by Nacho Soto on 1/16/24.
//

import Nimble
import RevenueCat
@testable import RevenueCatUI
import StoreKit
import XCTest

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
class LocalizedAlertGenericErrorTests: TestCase {

private static let error = LocalizedAlertError(
error: StoreKitError.networkError(URLError(.notConnectedToInternet)) as NSError
)

func testErrorDescription() {
expect(Self.error.errorDescription) == "StoreKit.StoreKitError 0"
}

func testFailureReason() {
expect(Self.error.failureReason) == "The operation couldn’t be completed. (NSURLErrorDomain error -1009.)"
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
class LocalizedAlertErrorCodeTests: TestCase {

private static let error = LocalizedAlertError(error: ErrorCode.storeProblemError as NSError)

func testErrorDescription() {
expect(Self.error.errorDescription) == "Error"
}

func testFailureReason() {
expect(Self.error.failureReason) == "Error 2: There was a problem with the App Store."
}

}