fix: tiny autumn improvements

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-12-24 20:40:03 +01:00
parent 1661975a94
commit be019e7445
2 changed files with 6 additions and 3 deletions

View File

@ -381,5 +381,7 @@ data class RateLimitResponse(@SerialName("retry_after") val retryAfter: Int) {
}
}
class HitRateLimitException(retryAfter: Int) :
Exception("Hit rate limit, retry after ${retryAfter}ms")
internal const val NO_RETRY_AFTER = Int.MIN_VALUE
class HitRateLimitException(retryAfter: Int = NO_RETRY_AFTER) :
Exception(if (retryAfter == NO_RETRY_AFTER) "Hit rate limit" else "Hit rate limit, retry after ${retryAfter}ms")

View File

@ -1,5 +1,6 @@
package chat.revolt.api.routes.microservices.autumn
import chat.revolt.api.HitRateLimitException
import chat.revolt.api.REVOLT_FILES
import chat.revolt.api.RevoltAPI
import chat.revolt.api.RevoltHttp
@ -67,7 +68,7 @@ suspend fun uploadToAutumn(
throw Exception(error.type)
} catch (e: Exception) {
if (response.status == HttpStatusCode.TooManyRequests) {
throw Exception("Rate limited")
throw HitRateLimitException()
}
if (response.status == HttpStatusCode.PayloadTooLarge) {
throw Exception("File too large")