diff --git a/Signal/src/ViewControllers/Registration/Onboarding/OnboardingPhoneNumberViewController.swift b/Signal/src/ViewControllers/Registration/Onboarding/OnboardingPhoneNumberViewController.swift index ca19adf4cf..b294530249 100644 --- a/Signal/src/ViewControllers/Registration/Onboarding/OnboardingPhoneNumberViewController.swift +++ b/Signal/src/ViewControllers/Registration/Onboarding/OnboardingPhoneNumberViewController.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2021 Open Whisper Systems. All rights reserved. +// Copyright (c) 2022 Open Whisper Systems. All rights reserved. // import UIKit @@ -598,7 +598,7 @@ public class RegistrationPhoneNumberViewController: OnboardingBaseViewController guard !willDismiss else { return } self.phoneNumberTextField.becomeFirstResponder() - if let error = error, error.httpStatusCode == 413 { + if let error = error, error.httpStatusCode == 413 || error.httpStatusCode == 429 { // If we're not handed a retry-after date directly from the server, either // use the existing date we already have or construct a new date 5 min from now let retryAfterDate = error.httpRetryAfterDate ?? { diff --git a/Signal/src/ViewControllers/Registration/RegistrationHelper.swift b/Signal/src/ViewControllers/Registration/RegistrationHelper.swift index 4923ffe83e..f382c3dc6a 100644 --- a/Signal/src/ViewControllers/Registration/RegistrationHelper.swift +++ b/Signal/src/ViewControllers/Registration/RegistrationHelper.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2021 Open Whisper Systems. All rights reserved. +// Copyright (c) 2022 Open Whisper Systems. All rights reserved. // import Foundation @@ -127,7 +127,7 @@ public class RegistrationHelper: Dependencies { title: NSLocalizedString("REGISTRATION_ERROR", comment: ""), message: NSLocalizedString("REGISTRATION_NON_VALID_NUMBER", comment: "")) - case let error where error.httpStatusCode == 413: + case let error where error.httpStatusCode == 413 || error.httpStatusCode == 429: completion?(false, error) OWSActionSheets.showActionSheet( title: nil, diff --git a/SignalServiceKit/src/Account/TSAccountManager.swift b/SignalServiceKit/src/Account/TSAccountManager.swift index 720ecf98f5..fd42b8d819 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.swift +++ b/SignalServiceKit/src/Account/TSAccountManager.swift @@ -319,7 +319,7 @@ extension TSAccountManager { return OWSError(error: .registrationTransferAvailable, description: message, isRetryable: false) - case 413: + case 413, 429: // In the case of the "rate limiting" error, we want to show the // "recovery suggestion", not the error's "description." let recoverySuggestion = NSLocalizedString("REGISTER_RATE_LIMITING_BODY", comment: "") diff --git a/SignalServiceKit/src/Messages/MessageSender.swift b/SignalServiceKit/src/Messages/MessageSender.swift index 02b00b58cb..44c0504c57 100644 --- a/SignalServiceKit/src/Messages/MessageSender.swift +++ b/SignalServiceKit/src/Messages/MessageSender.swift @@ -239,7 +239,7 @@ public extension MessageSender { if httpStatusCode == 404 { self.hadMissingDeviceError(recipientAddress: recipientAddress, deviceId: deviceId) return failure(MessageSenderError.missingDevice) - } else if httpStatusCode == 413 { + } else if httpStatusCode == 413 || httpStatusCode == 429 { return failure(MessageSenderError.prekeyRateLimit) } else if httpStatusCode == 428 { // SPAM TODO: Only retry messages with -hasRenderableContent diff --git a/SignalServiceKit/src/Messages/UD/OWSRequestMaker.swift b/SignalServiceKit/src/Messages/UD/OWSRequestMaker.swift index 9752908ca6..44201ca0bb 100644 --- a/SignalServiceKit/src/Messages/UD/OWSRequestMaker.swift +++ b/SignalServiceKit/src/Messages/UD/OWSRequestMaker.swift @@ -138,7 +138,7 @@ public class RequestMaker: NSObject { }.recover(on: .global()) { (error: Error) -> Promise in let statusCode = error.httpStatusCode ?? 0 - if statusCode == 413 { + if statusCode == 413 || statusCode == 429 { // We've hit rate limit; don't retry. throw error } @@ -192,7 +192,7 @@ public class RequestMaker: NSObject { wasSentByUD: isUDRequest, wasSentByWebsocket: false) }.recover(on: .global()) { (error: Error) -> Promise in - if error.httpStatusCode == 413 { + if error.httpStatusCode == 413 || error.httpStatusCode == 429 { // We've hit rate limit; don't retry. throw error } diff --git a/SignalServiceKit/src/Network/API/HTTPUtils.swift b/SignalServiceKit/src/Network/API/HTTPUtils.swift index 1990f44ab4..c241f70021 100644 --- a/SignalServiceKit/src/Network/API/HTTPUtils.swift +++ b/SignalServiceKit/src/Network/API/HTTPUtils.swift @@ -104,7 +104,7 @@ extension HTTPUtils { let error = buildServiceResponseError(description: description, recoverySuggestion: recoverySuggestion) return error - case 413: + case 413, 429: Logger.warn("Rate limit exceeded: \(request.httpMethod) \(requestUrl.absoluteString)") let description = NSLocalizedString("REGISTER_RATE_LIMITING_ERROR", comment: "") let recoverySuggestion = NSLocalizedString("REGISTER_RATE_LIMITING_BODY", comment: "") diff --git a/SignalServiceKit/src/Util/Profiles/BulkProfileFetch.swift b/SignalServiceKit/src/Util/Profiles/BulkProfileFetch.swift index f51c832e8b..4206a51cdf 100644 --- a/SignalServiceKit/src/Util/Profiles/BulkProfileFetch.swift +++ b/SignalServiceKit/src/Util/Profiles/BulkProfileFetch.swift @@ -228,7 +228,7 @@ public class BulkProfileFetch: NSObject { if error.isNetworkConnectivityFailure { Logger.warn("Error: \(error)") self.lastOutcomeMap[uuid] = UpdateOutcome(.networkFailure) - } else if error.httpStatusCode == 413 { + } else if error.httpStatusCode == 413 || error.httpStatusCode == 429 { Logger.error("Error: \(error)") self.lastOutcomeMap[uuid] = UpdateOutcome(.retryLimit) self.lastRateLimitErrorDate = Date() diff --git a/SignalServiceKit/src/Util/Profiles/ProfileFetcherJob.swift b/SignalServiceKit/src/Util/Profiles/ProfileFetcherJob.swift index bcb06407a1..debd434182 100644 --- a/SignalServiceKit/src/Util/Profiles/ProfileFetcherJob.swift +++ b/SignalServiceKit/src/Util/Profiles/ProfileFetcherJob.swift @@ -256,7 +256,7 @@ public class ProfileFetcherJob: NSObject { if error.httpStatusCode == 404 { return future.reject(ProfileFetchError.missing) } - if error.httpStatusCode == 413 { + if error.httpStatusCode == 413 || error.httpStatusCode == 429 { return future.reject(ProfileFetchError.rateLimit) }