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