Skip to content

Commit

Permalink
fix: throw exception rather than wait for ErrorException. This was th…
Browse files Browse the repository at this point in the history
…e case when the timetable was not set
  • Loading branch information
fredbradley committed May 17, 2024
1 parent 36e87b1 commit 286e054
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Controllers/TimetableStructureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected function setEndpoint(): void
* @return Collection
*
* @throws GuzzleException
* @throws Exception
*/
public function index(): Collection
{
Expand All @@ -40,7 +41,13 @@ public function index(): Collection

$decoded = json_decode($response->getBody()->getContents());

$week = collect($decoded)['timetableWeeks'][0];
$allWeeks = collect($decoded)['timetableWeeks'];

if (is_array($allWeeks) && count($allWeeks)) {
$week = $allWeeks[0];
} else {
throw new Exception('No timetable weeks found.', 400);
}

$days = $week->timetableDays;
$result = [];
Expand Down

0 comments on commit 286e054

Please sign in to comment.