Better handling of DB errors.

This commit is contained in:
James Cole
2022-06-10 06:00:01 +02:00
parent 86d15435a5
commit 1b2106d43b
4 changed files with 108 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ use ErrorException;
use FireflyIII\Jobs\MailError;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@@ -124,6 +125,14 @@ class Handler extends ExceptionHandler
return response()->view('errors.FireflyException', ['exception' => $e, 'debug' => $isDebug], 500);
}
// special view for database errors with extra instructions
if($e instanceof QueryException) {
$isDebug = config('app.debug');
return response()->view('errors.DatabaseException', ['exception' => $e, 'debug' => $isDebug], 500);
}
//var_dump($e);exit;
return parent::render($request, $e);
}

View File

@@ -33,6 +33,7 @@ return [
'be_right_back' => 'Be right back!',
'check_back' => 'Firefly III is down for some necessary maintenance. Please check back in a second.',
'error_occurred' => 'Whoops! An error occurred.',
'db_error_occurred' => 'Whoops! A database error occurred.',
'error_not_recoverable' => 'Unfortunately, this error was not recoverable :(. Firefly III broke. The error is:',
'error' => 'Error',
'error_location' => 'This error occured in file <span style="font-family: monospace;">:file</span> on line :line with code :code.',

View File

@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="{{ trans('config.html_language') }}">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow, noarchive, noodp, NoImageIndex, noydir">
<title>Firefly III Database Exception :(</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<base href="{{ route('index') }}/">
{# CSS things #}
{# libraries #}
<link href="v1/lib/bs/css/bootstrap.min.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css" nonce="{{ JS_NONCE }}">
<link href="v1/lib/fa/css/font-awesome.min.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css" nonce="{{ JS_NONCE }}">
<link href="v1/css/daterangepicker.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css" nonce="{{ JS_NONCE }}">
{# the theme #}
<link href="v1/lib/adminlte/css/AdminLTE.min.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css" nonce="{{ JS_NONCE }}">
<link href="v1/lib/adminlte/css/skins/skin-blue-light.min.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css" nonce="{{ JS_NONCE }}">
{# favicons #}
{% include('partials.favicons') %}
</head>
<body class="container">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
<h1><a href="{{ route('index') }}"><strong>Firefly</strong>III</a></h1>
</div>
</div>
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
<h3 class="text-info">{{ trans('errors.db_error_occurred') }}</h3>
</div>
</div>
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
<p>
{{ trans('errors.error_not_recoverable') }}
</p>
<p class="text-danger">
{{ exception.getMessage |default('General unknown errror') }}
</p>
<p>
{{ trans('errors.error_location', {file: exception.getFile, line: exception.getLine, code: exception.getCode })|raw }}
</p>
</div>
</div>
{% if not debug %}
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
<h4>
{{ trans('errors.more_info') }}
</h4>
<p>
{{ trans('errors.collect_info')|raw }}
{{ trans('errors.collect_info_more')|raw }}
</p>
<h4>
{{ trans('errors.github_help') }}
</h4>
<p>
{{ trans('errors.github_instructions')|raw }}
</p>
<ol>
<li>{{ trans('errors.use_search') }}</li>
<li>{{ trans('errors.include_info', { link: route('debug') })|raw }}</li>
<li>{{ trans('errors.tell_more') }}</li>
<li>{{ trans('errors.include_logs') }}</li>
<li>{{ trans('errors.what_did_you_do') }}</li>
</ol>
</div>
</div>
{% endif %}
{% if debug %}
<div class="row">
<div class="col-lg-10 col-lg-offset-1 col-md-12 col-sm-12 col-xs-12">
<h4>{{ trans('errors.error') }}</h4>
<p>
{{ trans('errors.error_location', {file: exception.getFile, line: exception.getLine, code: exception.getCode })|raw }}
</p>
<h4>
{{ trans('errors.stacktrace') }}
</h4>
<div style="font-family: monospace;font-size:11px;">
{{ exception.getTraceAsString|nl2br }}
</div>
</div>
</div>
{% endif %}
</body>
</html>

View File

@@ -42,6 +42,9 @@
<p class="text-danger">
{{ exception.getMessage |default('General unknown errror') }}
</p>
<p>
{{ trans('errors.error_location', {file: exception.getFile, line: exception.getLine, code: exception.getCode })|raw }}
</p>
</div>
</div>
{% if not debug %}