mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-10 05:11:25 +00:00
Catch some exceptions.
This commit is contained in:
@@ -31,6 +31,8 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Safe\Exceptions\FilesystemException;
|
||||
use Safe\Exceptions\JsonException;
|
||||
use Symfony\Component\Mailer\Exception\TransportException;
|
||||
|
||||
use function Safe\file_get_contents;
|
||||
@@ -125,11 +127,23 @@ class MailError extends Job implements ShouldQueue
|
||||
|
||||
if (!file_exists($file)) {
|
||||
Log::debug(sprintf('Wrote new file in "%s"', $file));
|
||||
file_put_contents($file, json_encode($limits, JSON_PRETTY_PRINT));
|
||||
try {
|
||||
file_put_contents($file, json_encode($limits, JSON_PRETTY_PRINT));
|
||||
} catch (FilesystemException $e) {
|
||||
Log::warning(sprintf('[a] Could not write file "%s": %s', $file, $e->getMessage()));
|
||||
} catch (JsonException $e) {
|
||||
Log::warning(sprintf('[b] Could not parse file "%s": %s', $file, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
if (file_exists($file)) {
|
||||
Log::debug(sprintf('Read file in "%s"', $file));
|
||||
$limits = json_decode(file_get_contents($file), true);
|
||||
try {
|
||||
$limits = json_decode(file_get_contents($file), true);
|
||||
} catch (FilesystemException $e) {
|
||||
Log::warning(sprintf('[c] Could not read file "%s": %s', $file, $e->getMessage()));
|
||||
} catch (JsonException $e) {
|
||||
Log::warning(sprintf('[d] Could not parse file "%s": %s', $file, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
// limit reached?
|
||||
foreach ($types as $type => $info) {
|
||||
@@ -157,7 +171,13 @@ class MailError extends Job implements ShouldQueue
|
||||
}
|
||||
++$limits[$type]['sent'];
|
||||
}
|
||||
file_put_contents($file, json_encode($limits, JSON_PRETTY_PRINT));
|
||||
try {
|
||||
file_put_contents($file, json_encode($limits, JSON_PRETTY_PRINT));
|
||||
} catch (FilesystemException $e) {
|
||||
Log::warning(sprintf('[c] Could not write file "%s": %s', $file, $e->getMessage()));
|
||||
} catch (JsonException $e) {
|
||||
Log::warning(sprintf('[c] Could not parse file "%s": %s', $file, $e->getMessage()));
|
||||
}
|
||||
Log::debug('No limits reached, return FALSE.');
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user