0

I have a function that calculates the aspect ratio of a height and a width input, and either throws an error, or returns an object with the aspect ratio.

var bestAR = dimensions.map(function(dim) {
    try {
       return findBestAR(dim.width, dim.height); 
    }
    catch (e) {
        return new Bacon.Error(e);
    }
});

bestAR.onError(function(e) {
    alert(e)
});

I can log the new Bacon.Error in my catch statement to the console and it contains the thrown error inside of findBestAR. However, it does not respond to the onError per Bacon. Maybe I'm not fully understanding how error handling in Bacon works.

yanana
  • 2,241
  • 2
  • 18
  • 28
Arik
  • 31
  • 3

1 Answers1

1

.map can only change value events into value events. To change a value event into an error event (or into a different number of events), you need to use .flatMap instead.

Macil
  • 3,575
  • 1
  • 20
  • 18