From 26901f82220fe18c0ad6e2bfc23c59b451a4e198 Mon Sep 17 00:00:00 2001 From: Frankie B Date: Fri, 8 Sep 2023 23:19:40 +0100 Subject: feat: add error handling (#14) * Remove commented out crap * Update theme to use some colors from catppuccin, add error handling for API/DB --- config/app.php | 1 - public/css/master.css | 28 +++++++++++++++------- .../views/components/errors/api-error.blade.php | 4 ++++ .../views/components/errors/db-error.blade.php | 4 ++++ resources/views/pages/bookmarks.blade.php | 14 ++++++++++- resources/views/pages/guestbook.blade.php | 16 +++++++++++-- resources/views/pages/music.blade.php | 14 +++++++++++ resources/views/pages/weather.blade.php | 19 ++++++++++++--- 8 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 resources/views/components/errors/api-error.blade.php create mode 100644 resources/views/components/errors/db-error.blade.php diff --git a/config/app.php b/config/app.php index 1066543..dfc65d4 100644 --- a/config/app.php +++ b/config/app.php @@ -28,6 +28,5 @@ return [ App\Providers\RouteServiceProvider::class, ])->toArray(), 'aliases' => Facade::defaultAliases()->merge([ - // 'Example' => App\Facades\Example::class, ])->toArray(), ]; diff --git a/public/css/master.css b/public/css/master.css index 24631ee..0e13965 100644 --- a/public/css/master.css +++ b/public/css/master.css @@ -1,6 +1,7 @@ :root { - --background: #1c1b22; - --foreground: #dddddd; + --background: #181926; + --foreground: #cad3f5; + --links: #8aadf4; } body { @@ -128,7 +129,7 @@ div.note { table { border-collapse: collapse; - border-color: #fff; + border-color: var(--foreground); } table.weather th { @@ -178,7 +179,7 @@ td { } .header .title { - color: #fff; + color: var(--foreground); } .header { @@ -186,7 +187,6 @@ td { font-weight: normal; padding-bottom: 0; text-align: center; - color: #ffffff; } h1 { @@ -224,7 +224,7 @@ table.commits tr td { } a { - color: #99f; + color: var(--links); text-decoration: none; } @@ -265,7 +265,7 @@ table.gb-entry-form tbody tr td textarea { } table.gb-entry tr td { - border: solid #ffffff 1px; + border: solid var(--foreground) 1px; width: 500px; vertical-align: top; padding: 5px; @@ -278,7 +278,7 @@ table.gb-entry { table.gb-admin { margin-bottom: 5px; width: 500px; - border: #fff solid; + border: var(--foreground) solid; } table.gb-admin tr td { @@ -371,3 +371,15 @@ a:hover { .computer-specs { margin-top: 5px; } + +.error-box { + width: 500px; + border: 5px solid #c81a11; + background-color: #f64a3c; + padding: 5px; +} +.error-box a, +.error-box p { + margin: 0; + color: var(--foreground) +} diff --git a/resources/views/components/errors/api-error.blade.php b/resources/views/components/errors/api-error.blade.php new file mode 100644 index 0000000..1d4609a --- /dev/null +++ b/resources/views/components/errors/api-error.blade.php @@ -0,0 +1,4 @@ +
+

API Error: There was an error connecting to the API.

+

If this error persists, please notify me via e-mail.

+
diff --git a/resources/views/components/errors/db-error.blade.php b/resources/views/components/errors/db-error.blade.php new file mode 100644 index 0000000..45f6157 --- /dev/null +++ b/resources/views/components/errors/db-error.blade.php @@ -0,0 +1,4 @@ +
+

DB Error: There was an error connecting to the database.

+

If this error persists, please notify me via e-mail.

+
diff --git a/resources/views/pages/bookmarks.blade.php b/resources/views/pages/bookmarks.blade.php index 54d464d..d7d8283 100644 --- a/resources/views/pages/bookmarks.blade.php +++ b/resources/views/pages/bookmarks.blade.php @@ -3,7 +3,18 @@ @section('description', 'This is the personal homepage of floppydisk.') @section('content') @php - $categories = DB::select(' + $db_alive = true; + try { + DB::connection()->getPdo(); + } catch (Exception $e) { + $db_alive = false; + } + @endphp + @if (!$db_alive) + @include('components.errors.db-error') + @else + @php + $categories = DB::select(' SELECT id, name FROM bookmark__categories ORDER BY priority ASC @@ -37,4 +48,5 @@
@endforeach + @endif @stop diff --git a/resources/views/pages/guestbook.blade.php b/resources/views/pages/guestbook.blade.php index 08bc7cb..13415b4 100644 --- a/resources/views/pages/guestbook.blade.php +++ b/resources/views/pages/guestbook.blade.php @@ -1,13 +1,24 @@ @extends('layouts.default') @section('title', 'Guestbook') @section('content') + @php + $db_alive = true; + try { + DB::connection()->getPdo(); + } catch (Exception $e) { + $db_alive = false; + } + @endphp + @if (!$db_alive) + @include('components.errors.db-error') + @else
@endforeach
@csrf - + @@ -74,4 +85,5 @@
@@ -44,7 +55,7 @@

A few things to note:

  • You can submit an entry once every hour.
  • -
  • Your IP address is logged but not publically displayed.
  • +
  • Your IP address is logged but not publicly displayed.
  • Any entries that appear to be spam will be removed.

@endforeach + @endif @stop diff --git a/resources/views/pages/music.blade.php b/resources/views/pages/music.blade.php index 3e97daa..775157a 100644 --- a/resources/views/pages/music.blade.php +++ b/resources/views/pages/music.blade.php @@ -7,6 +7,19 @@ $cfg = app('config')->get('services')['lastfm']; $api_root = app('config')->get('app')['api_root']; + $api_alive = true; + + try { + $data = file_get_contents($api_root.'/lastfm/current'); + } catch (Exception $e) { + $api_alive = false; + } + @endphp + @if (!$api_alive) + @include('components.errors.api-error') + @else + + @php $current_track = json_decode(file_get_contents($api_root . '/lastfm/current')); $top_tracks = json_decode(file_get_contents($api_root . '/lastfm/top')); $count = 0; @@ -51,4 +64,5 @@
+ @endif @stop diff --git a/resources/views/pages/weather.blade.php b/resources/views/pages/weather.blade.php index 823c448..369927f 100644 --- a/resources/views/pages/weather.blade.php +++ b/resources/views/pages/weather.blade.php @@ -13,10 +13,22 @@ function degreesToCompassDirection($degrees) { return $cardinalDirections[round($degrees*16/360)]; } -$data = json_decode(file_get_contents($api_root.'/weather')); -$updated = gmdate('H:i Y-m-d', $data->updated); -$data = $data->current; +$api_alive = true; + +try { + $data = file_get_contents($api_root.'/weather'); +} catch (Exception $e) { + $api_alive = false; +} @endphp +@if (!$api_alive) + @include('components.errors.api-error') +@else + @php + $data = json_decode(file_get_contents($api_root.'/weather')); + $updated = gmdate('H:i Y-m-d', $data->updated); + $data = $data->current; + @endphp

Local Weather

@@ -45,4 +57,5 @@ $data = $data->current;

(Last Update: {{ $updated }}) +@endif @stop -- cgit v1.2.3-54-g00ecf