Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Better error handling for issue #168
James Cole4d6e244100ab
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.phpindex 0286b50696..e39bfe16d1 100644--- a/app/Exceptions/Handler.php+++ b/app/Exceptions/Handler.php@@ -6,6 +6,10 @@ use Exception;use Illuminate\Auth\Access\AuthorizationException;use Illuminate\Database\Eloquent\ModelNotFoundException;use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;+use Illuminate\Mail\Message;+use Log;+use Mail;+use Swift_TransportException;use Symfony\Component\HttpKernel\Exception\HttpException;/**@@ -39,6 +43,34 @@ class Handler extends ExceptionHandler{if ($exception instanceof FireflyException) {+ // log+ Log::error($exception->getMessage());++ // mail?+ try {+ $email = env('SITE_OWNER');++ $args = [+ 'errorMessage' => $exception->getMessage(),+ 'stacktrace' => $exception->getTraceAsString(),+ 'file' => $exception->getFile(),+ 'line' => $exception->getLine(),+ 'code' => $exception->getCode(),+ ];++ Mail::send(+ ['emails.error-html', 'emails.error'], $args,+ function (Message $message) use ($email) {+ if ($email != '[email protected]') {+ $message->to($email, $email)->subject('Caught an error in Firely III.');+ }+ }+ );+ } catch (Swift_TransportException $e) {+ // could also not mail! :o+ Log::error($e->getMessage());+ }+return response()->view('errors.FireflyException', ['exception' => $exception], 500);}diff --git a/resources/views/emails/error-html.twig b/resources/views/emails/error-html.twignew file mode 100644index 0000000000..9893172ec2--- /dev/null+++ b/resources/views/emails/error-html.twig@@ -0,0 +1,31 @@+<!DOCTYPE html>+<html xmlns="http://www.w3.org/1999/xhtml">+<head>+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">++</head>+<body>+<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">+ Firefly III ran into an error: <span style="font-family: monospace;">{{ errorMessage }}</span>.+</p>+<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">+ This error occured in file <span style="font-family: monospace;">{{ file }}</span> on line {{ line }} with code {{ code }}.+</p>++<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">+ The full stacktrace is below. If you think this is a bug in Firefly III, you+ can forward this message to+ <a href="mailto:[email protected]?subject=BUG!">[email protected]</a>.+ This can help fix the bug you just encountered.+</p>+<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">+ If you prefer, you can also open a new issue on <a href="https://github.com/JC5/firefly-iii/issues/new">Github</a>.+</p>++<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">+ The full stacktrace is below:</p>+<p style="font-family: monospace;font-size:11px;color:#aaa">+ {{ stacktrace|nl2br }}+</p>+</body>+</html>diff --git a/resources/views/emails/error.twig b/resources/views/emails/error.twignew file mode 100644index 0000000000..0e30a0cd22--- /dev/null+++ b/resources/views/emails/error.twig@@ -0,0 +1,15 @@+Firefly III ran into an error: {{ errorMessage }}.++This error occured in file "{{ file }}" on line {{ line }} with code {{ code }}.++The full stacktrace is below. If you think this is a bug in Firefly III, you+can forward this message to [email protected]. This can help fix+the bug you just encountered.++If you prefer, you can also open a new issue here:++https://github.com/JC5/firefly-iii/issues/new++The full stacktrace is below:++{{ stacktrace }}\ No newline at end of file