Skip to content

Commit 778554f

Browse files
Merge pull request #4 from mr3y-the-programmer/rate_limit
Handle case when API rate limit has been reached
2 parents 3bce1a1 + 591a7cd commit 778554f

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

podcastindex-sdk/src/commonMain/kotlin/com/mr3y/podcastindex/extensions/SafeCall.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mr3y.podcastindex.extensions
22

33
import com.mr3y.podcastindex.model.BadRequestException
4+
import com.mr3y.podcastindex.model.RateLimitExceededException
45
import com.mr3y.podcastindex.model.UnknownException
56
import io.ktor.client.call.body
67
import io.ktor.client.statement.HttpResponse
@@ -18,6 +19,7 @@ internal suspend inline fun <reified T> withErrorHandling(block: () -> HttpRespo
1819
throw BadRequestException(description)
1920
}
2021
HttpStatusCode.Unauthorized -> throw IllegalStateException("You're Unauthenticated! Make sure to enter your authentication credentials correctly")
22+
HttpStatusCode.TooManyRequests -> throw RateLimitExceededException("API rate limit reached. Try again later or contact PodcastIndex org support if you think there is a mistake.")
2123
else -> throw UnknownException(response.bodyAsText())
2224
}
2325
}

podcastindex-sdk/src/commonMain/kotlin/com/mr3y/podcastindex/model/Exception.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ package com.mr3y.podcastindex.model
22

33
public class BadRequestException(override val message: String) : Exception(message)
44

5+
public class RateLimitExceededException(override val message: String) : Exception(message)
6+
57
public class UnknownException(override val message: String) : Exception(message)

0 commit comments

Comments
 (0)