Files
purchases-ios/RevenueCatUI/Data/LocalizedAlertError.swift
T
NachoSoto 56741f0a92 Paywalls: improve error display (#3577)
### Before:

This prevents "leaking" _RevenueCat_ in the error dialogs:

![Simulator Screenshot - iPhone 15 Pro Max - 2024-01-16 at 12 45
13](https://github.com/RevenueCat/purchases-ios/assets/685609/a59bce50-a470-44fb-9d36-1553abcc8488)

### After:
With this change, users still get some information about the problem,
and we get enough context to be able to diagnose it:

![Simulator Screenshot - iPhone 15 Pro Max - 2024-01-16 at 12 57
15](https://github.com/RevenueCat/purchases-ios/assets/685609/721d0197-5507-4618-9fe1-e0e748b0bc32)
2024-01-16 16:27:32 -08:00

46 lines
1.1 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// LocalizedAlertError.swift
//
// Created by Nacho Soto on 7/21/23.
import RevenueCat
import SwiftUI
struct LocalizedAlertError: LocalizedError {
private let underlyingError: NSError
init(error: NSError) {
self.underlyingError = error
}
var errorDescription: String? {
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 "Error \(self.underlyingError.code): \(errorCode.description)"
} else {
return self.underlyingError.localizedDescription
}
}
var recoverySuggestion: String? {
self.underlyingError.localizedRecoverySuggestion
}
}