diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 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 != 'mail@example.com') { + $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.twig new file mode 100644 index 0000000000..9893172ec2 --- /dev/null +++ b/resources/views/emails/error-html.twig @@ -0,0 +1,31 @@ + + + + + + + +

+ 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 + thegrumpydictator@gmail.com. + This can help fix the bug you just encountered. +

+

+ If you prefer, you can also open a new issue on Github. +

+ +

+ The full stacktrace is below:

+

+ {{ stacktrace|nl2br }} +

+ + diff --git a/resources/views/emails/error.twig b/resources/views/emails/error.twig new file mode 100644 index 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 thegrumpydictator@gmail.com. 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