diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index c5d1f86783..ec7be75546 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1624,9 +1624,6 @@ /* Error indicating that an outgoing message had no valid recipients. */ "ERROR_DESCRIPTION_NO_VALID_RECIPIENTS" = "Message send failed due to a lack of valid recipients."; -/* Error indicating that a socket request failed. */ -"ERROR_DESCRIPTION_REQUEST_FAILED" = "Network request failed."; - /* Error indicating that a socket request timed out. */ "ERROR_DESCRIPTION_REQUEST_TIMED_OUT" = "Network request timed out."; @@ -1702,12 +1699,6 @@ /* Format string for 'unregistered user' error. Embeds {{the unregistered user's name or signal id}}. */ "ERROR_UNREGISTERED_USER_FORMAT" = "Unregistered User: %@"; -/* A default error description. */ -"ERRORS_DEFAULT_ERROR_DESCRIPTION" = "Error"; - -/* A default error recovery suggestion. */ -"ERRORS_DEFAULT_ERROR_RECOVERY_DESCRIPTION" = "Please try again."; - /* Label notifying the user that the app has expired. */ "EXPIRATION_ERROR" = "Your version of Signal has expired! Tap to update to the most recent version."; @@ -4555,6 +4546,9 @@ /* No comment provided by engineer. */ "REGISTRATION_RESTRICTED_MESSAGE" = "You need to register before you can send a message."; +/* Error message indicating that device transfer from another device might be possible. */ +"REGISTRATION_TRANSFER_AVAILABLE_DESCRIPTION" = "There was an account previously registered with this number that is available for transfer."; + /* Alert view title */ "REGISTRATION_VERIFICATION_FAILED_TITLE" = "Verification Failed"; diff --git a/SignalServiceKit/src/Account/TSAccountManager.swift b/SignalServiceKit/src/Account/TSAccountManager.swift index da3d55a8e8..72a9fbe94a 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.swift +++ b/SignalServiceKit/src/Account/TSAccountManager.swift @@ -278,8 +278,8 @@ extension TSAccountManager { comment: "Error message indicating that registration failed due to a missing or incorrect verification code.") failure(OWSErrorWithCodeDescription(.userError, message)) case 409: - // TODO: Localize? - let message = "There was an account previously registered with this number that is available for transfer." + let message = NSLocalizedString("REGISTRATION_TRANSFER_AVAILABLE_DESCRIPTION", + comment: "Error message indicating that device transfer from another device might be possible.") failure(OWSErrorWithCodeDescription(.registrationTransferAvailable, message)) case 413: // In the case of the "rate limiting" error, we want to show the diff --git a/SignalServiceKit/src/Messages/MessageSender+Errors.swift b/SignalServiceKit/src/Messages/MessageSender+Errors.swift index 3740bdaa35..9a25378dc9 100644 --- a/SignalServiceKit/src/Messages/MessageSender+Errors.swift +++ b/SignalServiceKit/src/Messages/MessageSender+Errors.swift @@ -13,7 +13,6 @@ public enum MessageSenderError: Int, Error, IsRetryableProvider { case missingDevice case blockedContactRecipient case threadMissing - // TODO: EncryptionError.missingSession // MARK: - IsRetryableProvider @@ -122,7 +121,7 @@ public class MessageSenderNoSuchSignalRecipientError: NSObject, CustomNSError, I /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -173,7 +172,7 @@ public class MessageSenderErrorNoValidRecipients: NSObject, CustomNSError, IsRet /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -205,7 +204,7 @@ public class MessageSenderNoSessionForTransientMessageError: NSObject, CustomNSE /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -244,7 +243,7 @@ public class UntrustedIdentityError: NSObject, CustomNSError, IsRetryableProvide /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -289,7 +288,7 @@ public class SignalServiceRateLimitedError: NSObject, CustomNSError, IsRetryable /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -327,7 +326,7 @@ public class SpamChallengeRequiredError: NSObject, CustomNSError, IsRetryablePro /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -369,7 +368,7 @@ public class SpamChallengeResolvedError: NSObject, CustomNSError, IsRetryablePro /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -440,7 +439,7 @@ public class AppExpiredError: NSObject, CustomNSError, IsRetryableProvider { /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -477,7 +476,7 @@ public class AppDeregisteredError: NSObject, CustomNSError, IsRetryableProvider /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -517,7 +516,7 @@ public class MessageDeletedBeforeSentError: NSObject, CustomNSError, IsRetryable /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -544,7 +543,7 @@ public class SenderKeyEphemeralError: NSObject, CustomNSError, IsRetryableProvid /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -579,7 +578,7 @@ public class SenderKeyUnavailableError: NSObject, CustomNSError, IsRetryableProv /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -608,7 +607,7 @@ public class MessageSendUnauthorizedError: NSObject, CustomNSError, IsRetryableP /// NSError bridging: the domain of the error. /// :nodoc: @objc - public static let errorDomain = "SignalServiceKit.MessageSender" + public static let errorDomain = OWSSignalServiceKitErrorDomain /// NSError bridging: the error code within the given domain. /// :nodoc: @@ -633,3 +632,34 @@ public class MessageSendUnauthorizedError: NSObject, CustomNSError, IsRetryableP // No need to retry if we've been de-authed. public var isRetryableProvider: Bool { false } } + +// MARK: - + +@objc +public class MessageSendEncryptionError: NSObject, CustomNSError, IsRetryableProvider { + @objc + public let recipientAddress: SignalServiceAddress + @objc + public let deviceId: Int32 + + required init(recipientAddress: SignalServiceAddress, deviceId: Int32) { + self.recipientAddress = recipientAddress + self.deviceId = deviceId + } + + /// NSError bridging: the domain of the error. + /// :nodoc: + @objc + public static let errorDomain = OWSSignalServiceKitErrorDomain + + /// NSError bridging: the error code within the given domain. + /// :nodoc: + @objc + public static var errorCode: Int { OWSErrorCode.messageSendEncryptionFailure.rawValue } + + /// NSError bridging: the error code within the given domain. + /// :nodoc: + public var errorCode: Int { Self.errorCode } + + public var isRetryableProvider: Bool { true } +} diff --git a/SignalServiceKit/src/Messages/MessageSender.swift b/SignalServiceKit/src/Messages/MessageSender.swift index 330a859cdd..48626f98ba 100644 --- a/SignalServiceKit/src/Messages/MessageSender.swift +++ b/SignalServiceKit/src/Messages/MessageSender.swift @@ -1107,10 +1107,6 @@ extension MessageSender { } extension MessageSender { - private enum EncryptionError: Error { - case missingSession(recipientAddress: SignalServiceAddress, deviceId: Int32) - } - @objc(encryptedMessageForMessageSend:deviceId:transaction:error:) private func encryptedMessage(for messageSend: OWSMessageSend, deviceId: Int32, @@ -1123,7 +1119,7 @@ extension MessageSender { guard Self.sessionStore.containsActiveSession(for: recipientAddress, deviceId: deviceId, transaction: transaction) else { - throw EncryptionError.missingSession(recipientAddress: recipientAddress, deviceId: deviceId) + throw MessageSendEncryptionError(recipientAddress: recipientAddress, deviceId: deviceId) } guard let plainText = messageSend.plaintextContent else { throw OWSAssertionError("Missing message content") diff --git a/SignalServiceKit/src/Util/OWSError.h b/SignalServiceKit/src/Util/OWSError.h index e391ec02b2..0f0481b2db 100644 --- a/SignalServiceKit/src/Util/OWSError.h +++ b/SignalServiceKit/src/Util/OWSError.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN extern NSString *const OWSSignalServiceKitErrorDomain; // TODO: These error codes are somtimes persisted, so we should -// explicitly assign a value to every case in this enum. +// explicitly assign a value to every case in this enum. typedef NS_ENUM(NSInteger, OWSErrorCode) { OWSErrorCodeInvalidMethodParameters = 11, OWSErrorCodeUnableToProcessServerResponse = 12, @@ -67,7 +67,8 @@ typedef NS_ENUM(NSInteger, OWSErrorCode) { OWSErrorCodeFailedToDecryptDuplicateMessage, OWSErrorCodeServerRejectedSuspectedSpam, OWSErrorCodeSenderKeyEphemeralFailure, - OWSErrorCodeSenderKeyUnavailable + OWSErrorCodeSenderKeyUnavailable, + OWSErrorCodeMessageSendEncryptionFailure }; extern NSError *OWSErrorWithCodeDescription(OWSErrorCode code, NSString *description); @@ -75,13 +76,5 @@ extern NSError *OWSErrorWithUserInfo(OWSErrorCode code, NSDictionary *userInfo); extern NSError *OWSErrorMakeUnableToProcessServerResponseError(void); extern NSError *OWSErrorMakeAssertionError(NSString *descriptionFormat, ...); extern NSError *OWSErrorMakeGenericError(NSString *descriptionFormat, ...); -extern NSError *OWSErrorMakeMessageSendDisabledDueToPreKeyUpdateFailuresError(void); -extern NSError *OWSErrorMakeMessageSendFailedDueToBlockListError(void); - -@interface NSError (OWSError) - -- (BOOL)ows_isSSKErrorWithCode:(NSUInteger)code; - -@end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Util/OWSError.m b/SignalServiceKit/src/Util/OWSError.m index 7f0ead307a..4d86f5408f 100644 --- a/SignalServiceKit/src/Util/OWSError.m +++ b/SignalServiceKit/src/Util/OWSError.m @@ -48,30 +48,4 @@ NSError *OWSErrorMakeGenericError(NSString *descriptionFormat, ...) NSLocalizedString(@"ERROR_DESCRIPTION_UNKNOWN_ERROR", @"Worst case generic error message")); } - -NSError *OWSErrorMakeMessageSendDisabledDueToPreKeyUpdateFailuresError() -{ - return OWSErrorWithCodeDescription(OWSErrorCodeMessageSendDisabledDueToPreKeyUpdateFailures, - NSLocalizedString(@"ERROR_DESCRIPTION_MESSAGE_SEND_DISABLED_PREKEY_UPDATE_FAILURES", - @"Error message indicating that message send is disabled due to prekey update failures")); -} - -NSError *OWSErrorMakeMessageSendFailedDueToBlockListError() -{ - return OWSErrorWithCodeDescription(OWSErrorCodeMessageSendFailedToBlockList, - NSLocalizedString(@"ERROR_DESCRIPTION_MESSAGE_SEND_FAILED_DUE_TO_BLOCK_LIST", - @"Error message indicating that message send failed due to block list")); -} - -@implementation NSError (OWSError) - -- (BOOL)ows_isSSKErrorWithCode:(NSUInteger)code -{ - BOOL sameDomain = [self.domain isEqualToString:OWSSignalServiceKitErrorDomain]; - BOOL sameCode = (self.code == code); - return (sameDomain && sameCode); -} - -@end - NS_ASSUME_NONNULL_END