telegram
telegram copied to clipboard
Don't break the effect on exceptions
Currently, the processApiResponse call throws an exception (when an unexpected response is returned) which will kill the effect handling mechanism without the possibility to recover. This fix should fix that.
I pushed a first draft for the migration to sttp3 in https://github.com/bot4s/telegram/tree/sttp3 I translated as close as possible from the original implementation and that should also include this fix, however I would love to have a use case I can reproduce on this branch to test that the implementation is correct.
I pushed a first draft for the migration to sttp3 in https://github.com/bot4s/telegram/tree/sttp3 I translated as close as possible from the original implementation and that should also include this fix, however I would love to have a use case I can reproduce on this branch to test that the implementation is correct.
I'll try to build my new bot against your branch.. could u give me a one-liner on how I can build the jars with mill? I tried yesterday and was not able to do so... or maybe we can publish a snapshot or something.
You can publish all the jar locally by using the two following commands:
mill __.publishM2Local # Maven repo
mill __.publishLocal # Ivy repo
I'm atm writing tests and noticed, its working correctly with the original code using cats MonadError for Future, so I guess, my implementation of MonadError has a flaw or something. Please don't merge this yet, will keep you posted.
I'm pretty interested by this issue as I will try to finish my sttp3 update next week. I've added a simple test example https://github.com/bot4s/telegram/pull/110/commits/4fb380b04d1930af3a75a753ab2e3bc2594d722e to demonstrate how to use sttp stub in order to test the STTP client used in bots (I used Future client in this case).
I will try to add more tests in the future, but from my early experiments, it seems that my future is failing with a parsing failure when it can't read the response (400 or 500, the server is not even sending JSON back). And with a TelegramApiException when the server is responding with a JSON that contains an error (Unauthorized for instance).
@ex0ns I've been in contact with the guys from zio
https://github.com/zio/interop-cats/issues/330
and from what I got, the way to go (e.g. similar to what doobie and others do) should be to transform the def processApiResponse (and in best case every other place that throws exceptions) into something that does not throw an exception but returns a value, even if its just an Either[Throwable, A]
This is interesting, we could indeed avoid throwing exception in this part of the code. I'm pretty confident that the migration should be pretty easy to do as this is a protected method and is only used in a few places (less than 10 actually), would you like to try that ? Otherwise I'll take care of that next week
I can try to do a refactoring on the relevant parts on the weekend... just wasn't sure on how deep I'm allowed to grab into the code, so I tried with the smallest possible change first..
Any news on that ? I think I'll soon merge #110 as it does not seems to be breaking anything.
Hi @ex0ns! Sorry, I've been really busy. Please merge sttp3 at your convenience, I'll (re)base my changes on your branch or the latest master.