mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
improvement of exceptions
This commit is contained in:
parent
8bb2b5c218
commit
7b78dbdb3e
@ -14,6 +14,9 @@
|
|||||||
* Add `GetWebhookInfo` request and `WebhookInfo` type
|
* Add `GetWebhookInfo` request and `WebhookInfo` type
|
||||||
* Replace updates types into separated place in types
|
* Replace updates types into separated place in types
|
||||||
* Now default `RequestException` will contain plain answer from telegram
|
* Now default `RequestException` will contain plain answer from telegram
|
||||||
|
* Added `UnauthorizedException`
|
||||||
|
* `RequestException` now is sealed
|
||||||
|
* Rename `ReplyMessageNotFound` to `ReplyMessageNotFoundException`
|
||||||
|
|
||||||
## 0.11.0
|
## 0.11.0
|
||||||
|
|
||||||
|
@ -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)
|
|
@ -9,11 +9,12 @@ fun newRequestException(
|
|||||||
message: String? = null,
|
message: String? = null,
|
||||||
cause: Throwable? = null
|
cause: Throwable? = null
|
||||||
) = when (response.description) {
|
) = when (response.description) {
|
||||||
"Bad Request: reply message not found" -> ReplyMessageNotFound(response, plainAnswer, message, cause)
|
"Bad Request: reply message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause)
|
||||||
else -> RequestException(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 response: Response<*>,
|
||||||
val plainAnswer: String,
|
val plainAnswer: String,
|
||||||
message: String? = null,
|
message: String? = null,
|
||||||
@ -22,3 +23,18 @@ open class RequestException internal constructor(
|
|||||||
message,
|
message,
|
||||||
cause
|
cause
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in New Issue
Block a user