Add proper error messages

This commit is contained in:
Ben Goldsworthy 2023-01-14 21:02:31 +00:00
parent 97b85e1380
commit e81460781b
3 changed files with 42 additions and 11 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use DateTime;
use App\Mail\WeeklyDigest;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
@ -42,7 +43,16 @@ class TrackerController extends Controller
$toCheckin = $request->input('to', null);
$forceDownload = $request->input('force', false);
$tripData = $this->get_trip_data($tripId, $forceDownload);
try {
$tripData = $this->get_trip_data($tripId, $forceDownload);
} catch (ConnectException) {
return view(
'error',
[
'message' => "App timed out whilst downloading trip data from Wayward's servers. They may be down currently."
]
);
}
if ($fromCheckin) {
$tripData->checkins = array_filter(
@ -143,6 +153,7 @@ class TrackerController extends Controller
'base_uri' => 'https://app.wayward.travel/',
'timeout' => 20.0
]);
$response = $client->get('trip/'.($tripId ?? config('app.current_trip_id')).'/user/zmld8ko6qy7d9j3xvq10/json');
switch ($response->getStatusCode()) {
@ -177,8 +188,6 @@ class TrackerController extends Controller
return $data->trip;
default:
// TODO: Add proper error handling.
return "Something went wrong";
}
}

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html itemscope itemtype="https://schema.org/WebSite" lang="{{ str_replace('_', '-', app()->getLocale()) }}">
@include('partials.head')
<body>
<header>
<h1 class="page-title">Error</h1>
<p>{{ $message }}</p>
</header>
</body>
</html>

View File

@ -9,15 +9,23 @@
@php
if (preg_match("/\[\[([^\]]+)\]\]/", $checkin->note, $filepath)) {
if (preg_match("/\.webm/", $filepath[1])) {
$embed = '<video class="popup__video" controls>';
$embed .= '<source src="' . url("/videos/" . $filepath[1]) . '" type="video/webm">';
$embed .= '<p>Your browser doesn\'t support HTML video. Here is a <a href="' . url("/videos/" . $filepath[1]) . '">link to the video</a> instead.</p>';
$embed .= '</video>';
if (file_exists(public_path() . "/videos/" . $filepath[1])) {
$embed = '<video class="popup__video" controls>';
$embed .= '<source src="' . url("/videos/" . $filepath[1]) . '" type="video/webm">';
$embed .= '<p>Your browser doesn\'t support HTML video. Here is a <a href="' . url("/videos/" . $filepath[1]) . '">link to the video</a> instead.</p>';
$embed .= '</video>';
} else {
$embed = '<p>[This video has not yet been uploaded, try again later.]</p>';
}
} elseif (preg_match("/\.ogg/", $filepath[1])) {
$embed = '<audio class="popup__audio" controls>';
$embed .= '<source src="' . url("/audio/" . $filepath[1]) . '" type="audio/ogg">';
$embed .= '<p>Download <a href="' . url("/audio/" . $filepath[1]) . '">OGG</a> audio.</p>';
$embed .= '</audio>';
if (file_exists(public_path() . "/audio/" . $filepath[1])) {
$embed = '<audio class="popup__audio" controls>';
$embed .= '<source src="' . url("/audio/" . $filepath[1]) . '" type="audio/ogg">';
$embed .= '<p>Download <a href="' . url("/audio/" . $filepath[1]) . '">OGG</a> audio.</p>';
$embed .= '</audio>';
} else {
$embed = '<p>[This audio recording has not yet been uploaded, try again later.]</p>';
}
}
$checkin->note = preg_replace("/\[\[[^\]]+\]\]/", $embed, $checkin->note);
}