From 0f370ab667fabb6fe4eb56682cd3a24c23d881c5 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 4 Apr 2024 13:44:49 +1100 Subject: [PATCH] Changed the SnodeAPIError to be CustomStringConvertible --- Session/Home/New Conversation/NewDMVC.swift | 17 ++++---- SessionSnodeKit/Types/SnodeAPIError.swift | 46 ++++++++++----------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/Session/Home/New Conversation/NewDMVC.swift b/Session/Home/New Conversation/NewDMVC.swift index 850c2ae8b..371fe94de 100644 --- a/Session/Home/New Conversation/NewDMVC.swift +++ b/Session/Home/New Conversation/NewDMVC.swift @@ -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 ? diff --git a/SessionSnodeKit/Types/SnodeAPIError.swift b/SessionSnodeKit/Types/SnodeAPIError.swift index 5727c8ca0..fb2b2c62b 100644 --- a/SessionSnodeKit/Types/SnodeAPIError.swift +++ b/SessionSnodeKit/Types/SnodeAPIError.swift @@ -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)." } } }