mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-05-30 04:07:33 +00:00
Merge pull request #1042 from Dramex/fix/1008-too-many-requests-case-insensitive
Detect Too Many Requests case-insensitively (closes #1008)
This commit is contained in:
@@ -22,7 +22,7 @@ fun newRequestException(
|
||||
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
||||
description.contains("PHOTO_INVALID_DIMENSIONS") -> InvalidPhotoDimensionsException(response, plainAnswer, message, cause)
|
||||
description.contains("wrong file identifier") -> WrongFileIdentifierException(response, plainAnswer, message, cause)
|
||||
description.contains("Too Many Requests") -> TooMuchRequestsException(
|
||||
description.contains("Too Many Requests", ignoreCase = true) -> TooMuchRequestsException(
|
||||
(response.parameters ?.error as? RetryAfterError) ?: RetryAfterError(60, DateTime.now().unixMillisLong),
|
||||
response,
|
||||
plainAnswer,
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package dev.inmo.tgbotapi.bot.exceptions
|
||||
|
||||
import dev.inmo.tgbotapi.types.Response
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertIs
|
||||
|
||||
/**
|
||||
* Regression tests for https://github.com/InsanusMokrassar/TelegramBotAPI/issues/1008 —
|
||||
* Telegram's "Too Many Requests" response is case-inconsistent (both
|
||||
* `Too Many Requests` and `too Many Requests` have been observed), so the
|
||||
* description match must be case-insensitive.
|
||||
*/
|
||||
class NewRequestExceptionTests {
|
||||
private fun buildException(description: String) = newRequestException(
|
||||
response = Response(ok = false, description = description, errorCode = 429),
|
||||
plainAnswer = "{\"ok\":false}"
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `TooMuchRequestsException is created for canonical casing`() {
|
||||
assertIs<TooMuchRequestsException>(
|
||||
buildException("Bad Request: Too Many Requests: retry after 8")
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `TooMuchRequestsException is created for lowercase first-letter casing`() {
|
||||
assertIs<TooMuchRequestsException>(
|
||||
buildException("Bad Request: too Many Requests: retry after 8")
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `TooMuchRequestsException is created for all-lowercase casing`() {
|
||||
assertIs<TooMuchRequestsException>(
|
||||
buildException("Bad Request: too many requests: retry after 8")
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user