1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-03 00:15:27 +00:00
tgbotapi/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt

40 lines
1.5 KiB
Kotlin
Raw Normal View History

2019-02-10 05:41:20 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import java.io.IOException
fun newRequestException(
response: Response,
2019-03-04 02:32:26 +00:00
plainAnswer: String,
2019-02-10 05:41:20 +00:00
message: String? = null,
cause: Throwable? = null
) = when (response.description) {
2019-03-06 00:10:29 +00:00
"Bad Request: reply message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause)
"Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
else -> CommonRequestException(response, plainAnswer, message, cause)
2019-02-10 05:41:20 +00:00
}
2019-03-06 00:10:29 +00:00
sealed class RequestException constructor(
val response: Response,
2019-03-04 02:32:26 +00:00
val plainAnswer: String,
2019-02-10 05:41:20 +00:00
message: String? = null,
cause: Throwable? = null
) : IOException(
message,
cause
2019-03-06 00:10:29 +00:00
)
class CommonRequestException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
2019-03-06 00:10:29 +00:00
RequestException(response, plainAnswer, message, cause)
class UnauthorizedException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
2019-03-06 00:10:29 +00:00
RequestException(response, plainAnswer, message, cause)
class ReplyMessageNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
2019-03-06 00:10:29 +00:00
RequestException(response, plainAnswer, message, cause)
@Deprecated(
"Replaced by ReplyMessageNotFoundException",
ReplaceWith("ReplyMessageNotFoundException", "com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.ReplyMessageNotFoundException")
)
typealias ReplyMessageNotFound = ReplyMessageNotFoundException