From 1dc80f69298927fe2285f33065781739dc0d6e19 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 10 Feb 2019 13:41:20 +0800 Subject: [PATCH] replace of exceptions --- CHANGELOG.md | 1 + .../bot/Ktor/KtorRequestsExecutor.kt | 5 +++-- .../TelegramBotAPI/bot/RequestException.kt | 17 +++++++------- .../TelegramBotAPI/bot/RequestsExecutor.kt | 1 + .../bot/exceptions/ReplyMessageNotFound.kt | 6 +++++ .../bot/exceptions/RequestException.kt | 22 +++++++++++++++++++ .../utils/extensions/RequestsExecutor.kt | 2 +- 7 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/ReplyMessageNotFound.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index c9cc4f49bf..9e75892d38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Update some types and requests according to abstractions replacing * Add all `InlineQueryResult`, `InputMessageContent` and other inline mode types * Fixes in edition of inline messages and their result types +* Replace basic exception and add `ReplyMessageNotFound` exception ## 0.9.0 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt index a9c7e94aa1..8a25f9b59c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/KtorRequestsExecutor.kt @@ -3,7 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor import com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.MultipartRequestCallFactory import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.SimpleRequestCallFactory -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException +import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException +import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.newRequestException import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.EmptyLimiter import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestLimiter import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request @@ -75,7 +76,7 @@ class KtorRequestsExecutor( null } } ?: call.let { - throw RequestException( + throw newRequestException( responseObject, "Can't get result object" ) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestException.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestException.kt index f58666a347..58a8a1ef45 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestException.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestException.kt @@ -1,13 +1,14 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot +import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException import com.github.insanusmokrassar.TelegramBotAPI.types.Response import java.io.IOException -class RequestException( - val response: Response<*>, - message: String? = null, - cause: Throwable? = null -) : IOException( - message, - cause -) \ No newline at end of file +@Deprecated( + "Replaced to another package", + ReplaceWith( + "RequestException", + "com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException" + ) +) +typealias RequestException = RequestException \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt index 467185130b..e2eacbb377 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot +import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request interface RequestsExecutor { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/ReplyMessageNotFound.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/ReplyMessageNotFound.kt new file mode 100644 index 0000000000..0208179047 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/ReplyMessageNotFound.kt @@ -0,0 +1,6 @@ +package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions + +import com.github.insanusmokrassar.TelegramBotAPI.types.Response + +open class ReplyMessageNotFound(response: Response<*>, message: String?, cause: Throwable?) : + RequestException(response, message, cause) \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt new file mode 100644 index 0000000000..1783631604 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt @@ -0,0 +1,22 @@ +package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions + +import com.github.insanusmokrassar.TelegramBotAPI.types.Response +import java.io.IOException + +fun newRequestException( + response: Response<*>, + message: String? = null, + cause: Throwable? = null +) = when (response.description) { + "Bad Request: reply message not found" -> ReplyMessageNotFound(response, message, cause) + else -> RequestException(response, message, cause) +} + +open class RequestException internal constructor( + val response: Response<*>, + message: String? = null, + cause: Throwable? = null +) : IOException( + message, + cause +) \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/RequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/RequestsExecutor.kt index 4c3b8bf9f4..149db08c1c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/RequestsExecutor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/RequestsExecutor.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions -import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException +import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.* import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request