I have this http api that I'm trying to make beaut...
# coroutines
t
I have this http api that I'm trying to make beautiful. It's paginated, and any api call(page 1,2,3,4,5 etc) could 429. So I have N queries that I'm converting via a helper into a flow of the entities themselves. So callers get a Flow of entities instead of having to implement the loop logic. In the example I'm linking, it's a "service" that have 10 pages of Integers that it returns. It fails randomly. The structure is a flow that
emitAll
a flow that has the retry appended. Again, it's all working perfectly, but something seems just off about it.. Seems like too many flows. Thanks https://pl.kotl.in/ysrpoKNa7
The
makeACall
call inside the loop is the actual http call. pretent the repeat at the top is the doWhile loop that deals with the pagination and parameterizing the next http call
t
I had to do similar things to query the Spotify API, which also has rate limit and pagination ! My guess is that you could replace the innermost flow (the one performing the HTTP call) with a simple try/catch loop. Another approach is to configure an interceptor in your HTTP client to handle HTTP 429 errors by waiting the given amount.
t
I kind of like the flow variant. It's working quite well, and you can handle other transient errors simply there too. I just feel like I'm on the edge of making it beautiful.