These are chat archives for 47deg/fetch

Jul 2017
Justin Heyes-Jones
Jul 10 2017 18:28
Hi! I've been playing around with Fetch and it's a really neat library. One thing I didn't find in the docs that I ran into is handling failure. It seems like you can't propagate error information from your data source to the caller, so you don't know if an item is missing or if you just got a network timeout
Am I correct in thinking the API of Fetch and Haxl was never designed to handle missing elements; it's for use cases where you know for sure the item exists? In which case if I find missing elements I should just retry the whole fetch (and the cache will take care of making sure I don't duplicate requests)
Raúl Raja Martínez
Jul 10 2017 20:36
hi @justinhj ! Fetch uses Free in the underlying impl and its interpreter places a FetchMonadError constrain to any M[_] you are running it to.
You can create your own instances if you have a particular datatype you are running to that is not cats.Id or scala.concurrent.Future or monix.eval.Task
That MonadError instance fails fast and will you back a failed M[_]. for example if you are running to Future you will end up with a Future.failed(ex) as result of your fetch.
You can also lift any exceptions as errors while describing your fetches based on whatever arbitrary condition. For example:
val fetchException: Fetch[User] = (new Exception("Oh noes")).fetch
There is a section that describes error handling in more detail including the case of missing identities.
Tom Adams
Jul 10 2017 22:37
You can also return Option[T] from a fetch.
The type signature gets a bit whack but it’s possible.