1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

replace of exceptions

This commit is contained in:
InsanusMokrassar 2019-02-10 13:41:20 +08:00
parent 9f3d678528
commit 1dc80f6929
7 changed files with 43 additions and 11 deletions

View File

@ -9,6 +9,7 @@
* Update some types and requests according to abstractions replacing
* Add all `InlineQueryResult`, `InputMessageContent` and other inline mode types
* Fixes in edition of inline messages and their result types
* Replace basic exception and add `ReplyMessageNotFound` exception
## 0.9.0

View File

@ -3,7 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
import com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.MultipartRequestCallFactory
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base.SimpleRequestCallFactory
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.newRequestException
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.EmptyLimiter
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestLimiter
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
@ -75,7 +76,7 @@ class KtorRequestsExecutor(
null
}
} ?: call.let {
throw RequestException(
throw newRequestException(
responseObject,
"Can't get result object"
)

View File

@ -1,13 +1,14 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import java.io.IOException
class RequestException(
val response: Response<*>,
message: String? = null,
cause: Throwable? = null
) : IOException(
message,
cause
@Deprecated(
"Replaced to another package",
ReplaceWith(
"RequestException",
"com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException"
)
)
typealias RequestException = RequestException

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
interface RequestsExecutor {

View File

@ -0,0 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
open class ReplyMessageNotFound(response: Response<*>, message: String?, cause: Throwable?) :
RequestException(response, message, cause)

View File

@ -0,0 +1,22 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import java.io.IOException
fun newRequestException(
response: Response<*>,
message: String? = null,
cause: Throwable? = null
) = when (response.description) {
"Bad Request: reply message not found" -> ReplyMessageNotFound(response, message, cause)
else -> RequestException(response, message, cause)
}
open class RequestException internal constructor(
val response: Response<*>,
message: String? = null,
cause: Throwable? = null
) : IOException(
message,
cause
)

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
import com.github.insanusmokrassar.TelegramBotAPI.requests.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request