Skip to content

Commit

Permalink
catch money exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Mar 15, 2020
1 parent 996d60c commit c6276a8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/Traits/Currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace App\Traits;

use Akaunting\Money\Money;
use InvalidArgumentException;
use OutOfBoundsException;
use UnexpectedValueException;

trait Currencies
{
Expand All @@ -15,7 +18,13 @@ public function convert($method, $amount, $from, $to, $rate, $format = false)
return $format ? $money->format() : $money->getAmount();
}

$money = $money->$method((double) $rate);
try {
$money = $money->$method((double) $rate);
} catch (InvalidArgumentException | OutOfBoundsException | UnexpectedValueException $e) {
logger($e->getMessage());

return 0;
}

return $format ? $money->format() : $money->getAmount();
}
Expand Down

0 comments on commit c6276a8

Please sign in to comment.