From 7b78dbdb3e712edff246ffdd7f1a492393819da1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 6 Mar 2019 08:10:29 +0800 Subject: [PATCH] improvement of exceptions --- CHANGELOG.md | 3 +++ .../bot/exceptions/ReplyMessageNotFound.kt | 6 ----- .../bot/exceptions/RequestException.kt | 24 +++++++++++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/ReplyMessageNotFound.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b939bfef7..3ad725bd37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ * Add `GetWebhookInfo` request and `WebhookInfo` type * Replace updates types into separated place in types * Now default `RequestException` will contain plain answer from telegram +* Added `UnauthorizedException` +* `RequestException` now is sealed +* Rename `ReplyMessageNotFound` to `ReplyMessageNotFoundException` ## 0.11.0 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 deleted file mode 100644 index ae66d2d920..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/ReplyMessageNotFound.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions - -import com.github.insanusmokrassar.TelegramBotAPI.types.Response - -open class ReplyMessageNotFound(response: Response<*>, plainAnswer: String, message: String?, cause: Throwable?) : - RequestException(response, plainAnswer, 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 index 4f0d627927..777ccec5d7 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt @@ -9,11 +9,12 @@ fun newRequestException( message: String? = null, cause: Throwable? = null ) = when (response.description) { - "Bad Request: reply message not found" -> ReplyMessageNotFound(response, plainAnswer, message, cause) - else -> RequestException(response, plainAnswer, message, cause) + "Bad Request: reply message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause) + "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause) + else -> CommonRequestException(response, plainAnswer, message, cause) } -open class RequestException internal constructor( +sealed class RequestException constructor( val response: Response<*>, val plainAnswer: String, message: String? = null, @@ -21,4 +22,19 @@ open class RequestException internal constructor( ) : IOException( message, cause -) \ No newline at end of file +) + +class CommonRequestException(response: Response<*>, plainAnswer: String, message: String?, cause: Throwable?) : + RequestException(response, plainAnswer, message, cause) + +class UnauthorizedException(response: Response<*>, plainAnswer: String, message: String?, cause: Throwable?) : + RequestException(response, plainAnswer, message, cause) + +class ReplyMessageNotFoundException(response: Response<*>, plainAnswer: String, message: String?, cause: Throwable?) : + RequestException(response, plainAnswer, message, cause) + +@Deprecated( + "Replaced by ReplyMessageNotFoundException", + ReplaceWith("ReplyMessageNotFoundException", "com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.ReplyMessageNotFoundException") +) +typealias ReplyMessageNotFound = ReplyMessageNotFoundException \ No newline at end of file