From 3911af1f88026e80c47a41e64c651bcdad2c038b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 14 Feb 2018 10:32:54 -0800 Subject: [PATCH 1/3] Replace FLOOD_WAIT check with the version used in download messages --- .../kotlin/de/fabianonline/telegram_backup/DownloadManager.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt index ca60e7e..c338145 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt @@ -316,7 +316,7 @@ class DownloadManager(internal var client: TelegramClient?, p: DownloadProgressI try { _downloadMedia() } catch (e: RpcErrorException) { - if (e.getTag().startsWith("420: FLOOD_WAIT_")) { + if (e.getCode() == 420) { // FLOOD_WAIT completed = false Utils.obeyFloodWaitException(e) } else { @@ -428,7 +428,7 @@ class DownloadManager(internal var client: TelegramClient?, p: DownloadProgressI try { response = download_client!!.executeRpcQuery(req, dcID) as TLFile } catch (e: RpcErrorException) { - if (e.getTag().startsWith("420: FLOOD_WAIT_")) { + if (e.getCode() == 420) { // FLOOD_WAIT try_again = true Utils.obeyFloodWaitException(e) } else if (e.getCode() == 400) { From a34ba8a84c36cb4089669d10193d825158d139fe Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 14 Feb 2018 10:46:03 -0800 Subject: [PATCH 2/3] Continue to next iteration on FLOOD_WAIT error --- .../kotlin/de/fabianonline/telegram_backup/DownloadManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt index c338145..aae5757 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt @@ -431,6 +431,7 @@ class DownloadManager(internal var client: TelegramClient?, p: DownloadProgressI if (e.getCode() == 420) { // FLOOD_WAIT try_again = true Utils.obeyFloodWaitException(e) + continue // response is null since we didn't actually receive any data. Skip the rest of this iteration and try again. } else if (e.getCode() == 400) { //Somehow this file is broken. No idea why. Let's skip it for now return false From 3ee90ac6c69d6204523bc45ced6a45c46cee9dfd Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 14 Feb 2018 10:47:43 -0800 Subject: [PATCH 3/3] Reorder clause to prevent null pointer exception when response is null and try_again is true --- .../kotlin/de/fabianonline/telegram_backup/DownloadManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt index aae5757..42ca76a 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt @@ -450,7 +450,7 @@ class DownloadManager(internal var client: TelegramClient?, p: DownloadProgressI } catch (e: InterruptedException) { } - } while (offset < size && (response!!.getBytes().getData().size > 0 || try_again)) + } while (offset < size && (try_again || response!!.getBytes().getData().size > 0)) fos.close() if (offset < size) { System.out.println("Requested file $target with $size bytes, but got only $offset bytes.")