Changed the SnodeAPIError to be CustomStringConvertible

pull/960/head
Morgan Pretty 1 year ago
parent 4818a6d074
commit 0f370ab667

@ -221,17 +221,14 @@ final class NewDMVC: BaseVC, UIPageViewControllerDataSource, UIPageViewControlle
case .finished: break
case .failure(let error):
modalActivityIndicator.dismiss {
var messageOrNil: String?
if let error = error as? SnodeAPIError {
switch error {
case .decryptionFailed, .hashingFailed, .validationFailed:
messageOrNil = error.errorDescription
default: break
}
}
let message: String = {
if let messageOrNil: String = messageOrNil {
return messageOrNil
if let error = error as? SnodeAPIError {
switch error {
case .decryptionFailed, .hashingFailed, .validationFailed:
return "\(error)"
default: break
}
}
return (maybeSessionId?.prefix == .blinded15 || maybeSessionId?.prefix == .blinded25 ?

@ -5,7 +5,7 @@
import Foundation
import SessionUtilitiesKit
public enum SnodeAPIError: LocalizedError {
public enum SnodeAPIError: Error, CustomStringConvertible {
case clockOutOfSync
case snodePoolUpdatingFailed
case inconsistentSnodePools
@ -34,35 +34,35 @@ public enum SnodeAPIError: LocalizedError {
case unreachable
case unassociatedPubkey
public var errorDescription: String? {
public var description: String {
switch self {
case .clockOutOfSync: return "Your clock is out of sync with the Service Node network. Please check that your device's clock is set to automatic time."
case .snodePoolUpdatingFailed: return "Failed to update the Service Node pool."
case .inconsistentSnodePools: return "Received inconsistent Service Node pool information from the Service Node network."
case .noKeyPair: return "Missing user key pair."
case .signingFailed: return "Couldn't sign message."
case .signatureVerificationFailed: return "Failed to verify the signature."
case .invalidIP: return "Invalid IP."
case .responseFailedValidation: return "Response failed validation."
case .rateLimited: return "Rate limited."
case .missingSnodeVersion: return "Missing Service Node version."
case .unsupportedSnodeVersion(let version): return "Unsupported Service Node version: \(version)."
case .clockOutOfSync: return "Your clock is out of sync with the Service Node network. Please check that your device's clock is set to automatic time (SnodeAPIError.clockOutOfSync)."
case .snodePoolUpdatingFailed: return "Failed to update the Service Node pool (SnodeAPIError.snodePoolUpdatingFailed)."
case .inconsistentSnodePools: return "Received inconsistent Service Node pool information from the Service Node network (SnodeAPIError.inconsistentSnodePools)."
case .noKeyPair: return "Missing user key pair (SnodeAPIError.noKeyPair)."
case .signingFailed: return "Couldn't sign message (SnodeAPIError.signingFailed)."
case .signatureVerificationFailed: return "Failed to verify the signature (SnodeAPIError.signatureVerificationFailed)."
case .invalidIP: return "Invalid IP (SnodeAPIError.invalidIP)."
case .responseFailedValidation: return "Response failed validation (SnodeAPIError.responseFailedValidation)."
case .rateLimited: return "Rate limited (SnodeAPIError.rateLimited)."
case .missingSnodeVersion: return "Missing Service Node version (SnodeAPIError.missingSnodeVersion)."
case .unsupportedSnodeVersion(let version): return "Unsupported Service Node version: \(version) (SnodeAPIError.unsupportedSnodeVersion)."
// Onion Request Errors
case .emptySnodePool: return "Service Node pool is empty."
case .insufficientSnodes: return "Couldn't find enough Service Nodes to build a path."
case .ranOutOfRandomSnodes: return "Ran out of random snodes to send the request through."
case .emptySnodePool: return "Service Node pool is empty (SnodeAPIError.emptySnodePool)."
case .insufficientSnodes: return "Couldn't find enough Service Nodes to build a path (SnodeAPIError.insufficientSnodes)."
case .ranOutOfRandomSnodes: return "Ran out of random snodes to send the request through (SnodeAPIError.ranOutOfRandomSnodes)."
// ONS
case .decryptionFailed: return "Couldn't decrypt ONS name."
case .hashingFailed: return "Couldn't compute ONS name hash."
case .validationFailed: return "ONS name validation failed."
case .decryptionFailed: return "Couldn't decrypt ONS name (SnodeAPIError.decryptionFailed)."
case .hashingFailed: return "Couldn't compute ONS name hash (SnodeAPIError.hashingFailed)."
case .validationFailed: return "ONS name validation failed (SnodeAPIError.validationFailed)."
// Quic
case .invalidPayload: return "Invalid payload."
case .missingSecretKey: return "Missing secret key."
case .unreachable: return "The service node is unreachable."
case .unassociatedPubkey: return "The service node is no longer associated with the public key."
case .invalidPayload: return "Invalid payload (SnodeAPIError.invalidPayload)."
case .missingSecretKey: return "Missing secret key (SnodeAPIError.missingSecretKey)."
case .unreachable: return "The service node is unreachable (SnodeAPIError.unreachable)."
case .unassociatedPubkey: return "The service node is no longer associated with the public key (SnodeAPIError.unassociatedPubkey)."
}
}
}

Loading…
Cancel
Save