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

Response#parameters fixing

This commit is contained in:
InsanusMokrassar 2019-02-05 12:51:52 +08:00
parent 206b3fd3e4
commit c4f0ed4b48
4 changed files with 49 additions and 15 deletions

View File

@ -26,6 +26,9 @@ must be regular text
* `RequestsExecutor#executeAsync(Request, CoroutineScope)` now will return `Deferred` for cases when you need result * `RequestsExecutor#executeAsync(Request, CoroutineScope)` now will return `Deferred` for cases when you need result
* `RequestsExecutor#executeUnsafe` will automatically retry request if it was unsuccessful and retries > 0 * `RequestsExecutor#executeUnsafe` will automatically retry request if it was unsuccessful and retries > 0
* Add `RequestError` sealed class and described in documentation known errors
* Add `ResponseParametersRaw` which can create error based on input parameters
* Add `parameters` field in `Response` and remove useless fields from `Response`
### 0.9.3 ### 0.9.3

View File

@ -0,0 +1,18 @@
package com.github.insanusmokrassar.TelegramBotAPI.types
import java.util.concurrent.TimeUnit
sealed class RequestError
data class RetryAfterError(
val seconds: Long,
val startCountingMillis: Long
) : RequestError() {
val canContinue = TimeUnit.SECONDS.toMillis(seconds) + startCountingMillis
}
data class MigrateChatId(
val newChatId: ChatId
) : RequestError()

View File

@ -15,22 +15,11 @@ data class Response<T : Any>(
val ok: Boolean = false, val ok: Boolean = false,
@Optional @Optional
val description: String? = null, val description: String? = null,
@SerialName("migrate_to_chat_id")
@Optional
val migrateToChatId: Identifier? = null,
@SerialName("retry_after")
@Optional
val retryAfter: Int? = null,
@SerialName("error_code") @SerialName("error_code")
@Optional @Optional
val errorCode: Int? = null, val errorCode: Int? = null,
@Optional @Optional
val result: T? = null val result: T? = null,
) { @Optional
@Transient val parameters: ResponseParametersRaw? = null
val waitUntil: DateTime? by lazy { )
retryAfter ?.let {
DateTime.now().plus(TimeUnit.SECONDS.toMillis(it.toLong()))
}
}
}

View File

@ -0,0 +1,24 @@
package com.github.insanusmokrassar.TelegramBotAPI.types
import kotlinx.serialization.*
@Serializable
data class ResponseParametersRaw(
@SerialName("migrate_to_chat_id")
@Optional
private val migrateToChatId: ChatId? = null,
@SerialName("retry_after")
@Optional
private val retryAfter: Long? = null
) {
@Transient
private val createTime: Long = System.currentTimeMillis()
val error: RequestError? by lazy {
when {
migrateToChatId != null -> MigrateChatId(migrateToChatId);
retryAfter != null -> RetryAfterError(retryAfter, createTime);
else -> null
}
}
}