2016-01-08 09:02:15 -06:00
|
|
|
<?php
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2016-01-08 09:02:15 -06:00
|
|
|
namespace FireflyIII\Exceptions;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2016-02-12 07:15:49 -06:00
|
|
|
use Auth;
|
2016-02-11 01:11:26 -06:00
|
|
|
use ErrorException;
|
2015-02-05 21:39:52 -06:00
|
|
|
use Exception;
|
2016-01-08 09:02:15 -06:00
|
|
|
use Illuminate\Auth\Access\AuthorizationException;
|
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
2016-02-10 08:18:13 -06:00
|
|
|
use Illuminate\Mail\Message;
|
|
|
|
use Log;
|
|
|
|
use Mail;
|
2016-02-11 07:20:18 -06:00
|
|
|
use Request;
|
2016-02-10 08:18:13 -06:00
|
|
|
use Swift_TransportException;
|
2016-01-09 01:20:55 -06:00
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
2016-02-12 07:15:49 -06:00
|
|
|
|
2016-01-09 01:20:55 -06:00
|
|
|
/**
|
|
|
|
* Class Handler
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Exceptions
|
|
|
|
*/
|
2015-02-11 00:35:10 -06:00
|
|
|
class Handler extends ExceptionHandler
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* A list of the exception types that should not be reported.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-01-09 01:20:55 -06:00
|
|
|
protected $dontReport
|
|
|
|
= [
|
|
|
|
AuthorizationException::class,
|
|
|
|
HttpException::class,
|
|
|
|
ModelNotFoundException::class,
|
|
|
|
];
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
2016-01-27 11:31:44 -06:00
|
|
|
* Render an exception into an HTTP response.
|
2015-02-11 00:35:10 -06:00
|
|
|
*
|
2016-01-27 11:31:44 -06:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Exception $exception
|
2016-01-09 01:20:55 -06:00
|
|
|
*
|
2016-01-27 11:31:44 -06:00
|
|
|
* @return \Illuminate\Http\Response
|
2015-02-11 00:35:10 -06:00
|
|
|
*/
|
2016-01-27 11:31:44 -06:00
|
|
|
public function render($request, Exception $exception)
|
2015-02-11 00:35:10 -06:00
|
|
|
{
|
2016-02-11 07:17:11 -06:00
|
|
|
if ($exception instanceof FireflyException || $exception instanceof ErrorException) {
|
|
|
|
|
|
|
|
$isDebug = env('APP_DEBUG', false);
|
|
|
|
|
|
|
|
return response()->view('errors.FireflyException', ['exception' => $exception, 'debug' => $isDebug], 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::render($request, $exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report or log an exception.
|
|
|
|
*
|
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
|
|
|
*
|
|
|
|
* @param Exception $exception
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function report(Exception $exception)
|
|
|
|
{
|
|
|
|
|
2016-02-11 01:11:26 -06:00
|
|
|
if ($exception instanceof FireflyException || $exception instanceof ErrorException) {
|
2016-02-05 22:01:34 -06:00
|
|
|
|
2016-02-10 08:18:13 -06:00
|
|
|
// mail?
|
|
|
|
try {
|
|
|
|
$email = env('SITE_OWNER');
|
2016-02-12 07:15:49 -06:00
|
|
|
$user = Auth::user();
|
|
|
|
$args = [
|
2016-02-10 08:18:13 -06:00
|
|
|
'errorMessage' => $exception->getMessage(),
|
|
|
|
'stacktrace' => $exception->getTraceAsString(),
|
|
|
|
'file' => $exception->getFile(),
|
|
|
|
'line' => $exception->getLine(),
|
|
|
|
'code' => $exception->getCode(),
|
2016-02-11 07:13:23 -06:00
|
|
|
'loggedIn' => !is_null($user),
|
|
|
|
'user' => $user,
|
2016-02-11 07:20:18 -06:00
|
|
|
'ip' => Request::ip(),
|
2016-02-11 07:13:23 -06:00
|
|
|
|
2016-02-10 08:18:13 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2016-02-05 22:01:34 -06:00
|
|
|
}
|
|
|
|
|
2016-01-27 11:31:44 -06:00
|
|
|
parent::report($exception);
|
2015-02-11 00:35:10 -06:00
|
|
|
}
|
2015-02-05 21:39:52 -06:00
|
|
|
}
|