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(
|
2019-08-17 05:50:46 +00:00
|
|
|
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(
|
2019-08-17 05:50:46 +00:00
|
|
|
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
|
|
|
)
|
|
|
|
|
2019-08-17 05:50:46 +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)
|
|
|
|
|
2019-08-17 05:50:46 +00:00
|
|
|
class UnauthorizedException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
2019-03-06 00:10:29 +00:00
|
|
|
RequestException(response, plainAnswer, message, cause)
|
|
|
|
|
2019-08-17 05:50:46 +00:00
|
|
|
class ReplyMessageNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
2019-03-06 00:10:29 +00:00
|
|
|
RequestException(response, plainAnswer, message, cause)
|