-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't break the effect on exceptions #106
Conversation
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.
response | ||
.map(_.unsafeBody) | ||
.map(processApiResponse[R]) | ||
monadError.flatMap(monadError.map(response)(_.unsafeBody))(t => monadError.fromTry(Try(processApiResponse[R](t)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good, however, could you please create an intermediate variable for readability.
val extractedBody = monadError.map(response)(_.unsafeBody)
monadError
.flatMap(extractedBody)(t => monadError.fromTry(Try(processApiResponse[R](t))))
Thanks !
Also, could you provide a setup in which such an error could happen ? (we don't have tests for this class, but I would like to keep track of this kind of issue for the future)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to get one during the week, have a busy day tomorrow and its already late now. The case where this happens is basically anywhere where the telegram api returns an error, e.g. as in my repo, when the bot tries to create an invite link, but has not the right permissions in the room for that, then telegram-api returns a 400.
I pushed a first draft for the migration to sttp3 in https://github.com/bot4s/telegram/tree/sttp3 |
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:
|
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 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 |
@ex0ns I've been in contact with the guys from zio |
This is interesting, we could indeed avoid throwing exception in this part of the code. |
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! |
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.