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";
}
}