Catch and verify various errors

This commit is contained in:
James Cole
2023-01-21 12:21:06 +01:00
parent c269913510
commit f9daf7751a
12 changed files with 33 additions and 27 deletions

View File

@@ -139,17 +139,17 @@ class FixTransactionTypes extends Command
}
);
if (0 === $collection->count()) {
throw new FireflyException(sprintf('Journal #%d has no source transaction.', $journal->id));
throw new FireflyException(sprintf('300001: Journal #%d has no source transaction.', $journal->id));
}
if (1 !== $collection->count()) {
throw new FireflyException(sprintf('Journal #%d has multiple source transactions.', $journal->id));
throw new FireflyException(sprintf('300002: Journal #%d has multiple source transactions.', $journal->id));
}
/** @var Transaction $transaction */
$transaction = $collection->first();
/** @var Account|null $account */
$account = $transaction->account;
if (null === $account) {
throw new FireflyException(sprintf('Journal #%d, transaction #%d has no source account.', $journal->id, $transaction->id));
throw new FireflyException(sprintf('300003: Journal #%d, transaction #%d has no source account.', $journal->id, $transaction->id));
}
return $account;
@@ -169,17 +169,17 @@ class FixTransactionTypes extends Command
}
);
if (0 === $collection->count()) {
throw new FireflyException(sprintf('Journal #%d has no destination transaction.', $journal->id));
throw new FireflyException(sprintf('300004: Journal #%d has no destination transaction.', $journal->id));
}
if (1 !== $collection->count()) {
throw new FireflyException(sprintf('Journal #%d has multiple destination transactions.', $journal->id));
throw new FireflyException(sprintf('300005: Journal #%d has multiple destination transactions.', $journal->id));
}
/** @var Transaction $transaction */
$transaction = $collection->first();
/** @var Account|null $account */
$account = $transaction->account;
if (null === $account) {
throw new FireflyException(sprintf('Journal #%d, transaction #%d has no destination account.', $journal->id, $transaction->id));
throw new FireflyException(sprintf('300006: Journal #%d, transaction #%d has no destination account.', $journal->id, $transaction->id));
}
return $account;

View File

@@ -249,7 +249,7 @@ class ExportData extends Command
}
}
if (0 === $final->count()) {
throw new FireflyException('Ended up with zero valid accounts to export from.');
throw new FireflyException('300007: Ended up with zero valid accounts to export from.');
}
return $final;

View File

@@ -48,7 +48,7 @@ trait VerifiesAccessToken
$repository = app(UserRepositoryInterface::class);
$user = $repository->find($userId);
if (null === $user) {
throw new FireflyException('User is unexpectedly NULL');
throw new FireflyException('300000: User is unexpectedly NULL');
}
return $user;