Catch the error in #760

This commit is contained in:
James Cole
2017-08-13 12:37:09 +02:00
parent ec636c95a1
commit f9c85d4d81
3 changed files with 8 additions and 2 deletions

View File

@@ -85,6 +85,7 @@ class ImportJournal
/** /**
* @return string * @return string
* @throws FireflyException
*/ */
public function getAmount(): string public function getAmount(): string
{ {
@@ -102,6 +103,9 @@ class ImportJournal
} }
} }
} }
if(bccomp($this->amount,'0') === 0) {
throw new FireflyException('Amount is zero.');
}
return $this->amount; return $this->amount;
} }

View File

@@ -11,6 +11,8 @@ declare(strict_types=1);
namespace FireflyIII\Import\Storage; namespace FireflyIII\Import\Storage;
use ErrorException;
use Exception;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Object\ImportJournal; use FireflyIII\Import\Object\ImportJournal;
use FireflyIII\Models\ImportJob; use FireflyIII\Models\ImportJob;
@@ -95,7 +97,7 @@ class ImportStorage
function (ImportJournal $importJournal, int $index) { function (ImportJournal $importJournal, int $index) {
try { try {
$this->storeImportJournal($index, $importJournal); $this->storeImportJournal($index, $importJournal);
} catch (FireflyException $e) { } catch (FireflyException | ErrorException | Exception $e) {
$this->errors->push($e->getMessage()); $this->errors->push($e->getMessage());
Log::error(sprintf('Cannot import row #%d because: %s', $index, $e->getMessage())); Log::error(sprintf('Cannot import row #%d because: %s', $index, $e->getMessage()));
} }

View File

@@ -214,7 +214,7 @@ trait ImportSupport
*/ */
private function getTransactionType(string $amount, Account $account): string private function getTransactionType(string $amount, Account $account): string
{ {
$transactionType = ''; $transactionType = TransactionType::WITHDRAWAL;
// amount is negative, it's a withdrawal, opposing is an expense: // amount is negative, it's a withdrawal, opposing is an expense:
if (bccomp($amount, '0') === -1) { if (bccomp($amount, '0') === -1) {
$transactionType = TransactionType::WITHDRAWAL; $transactionType = TransactionType::WITHDRAWAL;