3

I've defined the following Duct:

val augmenter1 = new Augmenter1
val augmenter2 = new Augmenter2
val augmenter3 = new Augmenter3
val defaultEventAugmenterPipeline: Duct[Event, Event] = Duct[Event].
    map(augmenter1.augment).
    map(augmenter2.augment).
    map(augmenter3.augment)

and Flow:

Flow(eventConsumer).append(defaultEventAugmenterPipeline).onComplete(materializer) { ... }

and an Augmenter looks like this:

class Augmenter1 extends Augmenter[Event] {
   def augment(e: Event): Event = {
      if(someCondition)
         e.addAugmentation(...)
      else
         throw new Exception("someCondition not met!")
      e
   }
}

Now, if the condition that leads to the exception in Augmenter1 is met, the flow simply terminates (successfully) at the first instance of the exception, without throwing any exception. I'd like to be able to do 2 things: catch the exception up the chain, and skip to the next event.

My question: what is the proper way to deal with errors/exceptions in a flow ?

Thanks

user650839
  • 2,594
  • 1
  • 13
  • 9
FabioC
  • 91
  • 5
  • 2
    My suggestion would be: use exceptions only for errorneous conditions that should cancel the stream. If the condition isn't really an exception but something that's expected with some probability, then make it part of the data-type (or create or use a wrapper data-type like Try/Either or one from scalaz). – jrudolph Sep 01 '14 at 14:15
  • @jrudolph, my issue is that the exception is NOT thrown. The flow simply terminates. But I might go with the idea of making it part of the data type. – FabioC Sep 01 '14 at 14:19
  • @FabioC How do you know that it terminates successfully? – Viktor Klang Sep 01 '14 at 22:39

0 Answers0