Closed jz4112 closed 10 years ago
Should switch these to Eithers
@alexanderdean In the oerClient class, when I do API request with the invalid date, I used an if statement to decide whether to throw an exception. if (date.isBefore(new DateTime(1999,1,1,0,0)) || date.isAfter(DateTime.now)) { throw new UnavailableExchangeRateException("exchange rate unavailable on the date[%s]".format(date)) }
When I call the method in the main class, I used try catch clause to return a Left with the messge
case (e: UnavailableExchangeRateException) => Left(e.msg)
is this right?
Hi @jz4112 - this is a good start. However, it would be cleaner to update OerClient to return an Either itself, rather than throwing an Exception in OerClient and then converting it to an Either in Forex.
In other words: it's best not to use Exceptions when you can use Eithers.
throw unavailbleException for eod loopup and conversion with illegal dates