1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-01 23:45:25 +00:00
tgbotapi/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/RequestException.kt

35 lines
1.3 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
2019-12-03 05:07:25 +00:00
import kotlinx.io.errors.IOException
2019-02-10 05:41:20 +00:00
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(
2019-12-03 05:07:25 +00:00
message ?: "Something went wrong",
2019-02-10 05:41:20 +00:00
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)