Add proper error messages
This commit is contained in:
parent
97b85e1380
commit
e81460781b
3 changed files with 42 additions and 11 deletions
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use App\Mail\WeeklyDigest;
|
use App\Mail\WeeklyDigest;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\ConnectException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
@ -42,7 +43,16 @@ class TrackerController extends Controller
|
||||||
$toCheckin = $request->input('to', null);
|
$toCheckin = $request->input('to', null);
|
||||||
$forceDownload = $request->input('force', false);
|
$forceDownload = $request->input('force', false);
|
||||||
|
|
||||||
|
try {
|
||||||
$tripData = $this->get_trip_data($tripId, $forceDownload);
|
$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) {
|
if ($fromCheckin) {
|
||||||
$tripData->checkins = array_filter(
|
$tripData->checkins = array_filter(
|
||||||
|
@ -143,6 +153,7 @@ class TrackerController extends Controller
|
||||||
'base_uri' => 'https://app.wayward.travel/',
|
'base_uri' => 'https://app.wayward.travel/',
|
||||||
'timeout' => 20.0
|
'timeout' => 20.0
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $client->get('trip/'.($tripId ?? config('app.current_trip_id')).'/user/zmld8ko6qy7d9j3xvq10/json');
|
$response = $client->get('trip/'.($tripId ?? config('app.current_trip_id')).'/user/zmld8ko6qy7d9j3xvq10/json');
|
||||||
|
|
||||||
switch ($response->getStatusCode()) {
|
switch ($response->getStatusCode()) {
|
||||||
|
@ -177,8 +188,6 @@ class TrackerController extends Controller
|
||||||
|
|
||||||
return $data->trip;
|
return $data->trip;
|
||||||
default:
|
default:
|
||||||
// TODO: Add proper error handling.
|
|
||||||
return "Something went wrong";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
resources/views/error.blade.php
Normal file
14
resources/views/error.blade.php
Normal 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>
|
|
@ -9,15 +9,23 @@
|
||||||
@php
|
@php
|
||||||
if (preg_match("/\[\[([^\]]+)\]\]/", $checkin->note, $filepath)) {
|
if (preg_match("/\[\[([^\]]+)\]\]/", $checkin->note, $filepath)) {
|
||||||
if (preg_match("/\.webm/", $filepath[1])) {
|
if (preg_match("/\.webm/", $filepath[1])) {
|
||||||
|
if (file_exists(public_path() . "/videos/" . $filepath[1])) {
|
||||||
$embed = '<video class="popup__video" controls>';
|
$embed = '<video class="popup__video" controls>';
|
||||||
$embed .= '<source src="' . url("/videos/" . $filepath[1]) . '" type="video/webm">';
|
$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 .= '<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>';
|
$embed .= '</video>';
|
||||||
|
} else {
|
||||||
|
$embed = '<p>[This video has not yet been uploaded, try again later.]</p>';
|
||||||
|
}
|
||||||
} elseif (preg_match("/\.ogg/", $filepath[1])) {
|
} elseif (preg_match("/\.ogg/", $filepath[1])) {
|
||||||
|
if (file_exists(public_path() . "/audio/" . $filepath[1])) {
|
||||||
$embed = '<audio class="popup__audio" controls>';
|
$embed = '<audio class="popup__audio" controls>';
|
||||||
$embed .= '<source src="' . url("/audio/" . $filepath[1]) . '" type="audio/ogg">';
|
$embed .= '<source src="' . url("/audio/" . $filepath[1]) . '" type="audio/ogg">';
|
||||||
$embed .= '<p>Download <a href="' . url("/audio/" . $filepath[1]) . '">OGG</a> audio.</p>';
|
$embed .= '<p>Download <a href="' . url("/audio/" . $filepath[1]) . '">OGG</a> audio.</p>';
|
||||||
$embed .= '</audio>';
|
$embed .= '</audio>';
|
||||||
|
} else {
|
||||||
|
$embed = '<p>[This audio recording has not yet been uploaded, try again later.]</p>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$checkin->note = preg_replace("/\[\[[^\]]+\]\]/", $embed, $checkin->note);
|
$checkin->note = preg_replace("/\[\[[^\]]+\]\]/", $embed, $checkin->note);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue