Browse Source

catch bad stop/route pair

tags/v1.0.0
Robin Thoni 8 years ago
parent
commit
ebbe33f1c9
1 changed files with 16 additions and 4 deletions
  1. 16
    4
      app/Business/SchedulesBusiness.php

+ 16
- 4
app/Business/SchedulesBusiness.php View File

14
 use App\Dbo\StopsLiteRoutesLiteDboArray;
14
 use App\Dbo\StopsLiteRoutesLiteDboArray;
15
 use App\Dbo\StopsSchedulesDbo;
15
 use App\Dbo\StopsSchedulesDbo;
16
 use Carbon\Carbon;
16
 use Carbon\Carbon;
17
+use GuzzleHttp\Exception\ClientException;
17
 use Luticate\Utils\Dbo\LuPaginatedDbo;
18
 use Luticate\Utils\Dbo\LuPaginatedDbo;
18
 
19
 
19
 class SchedulesBusiness
20
 class SchedulesBusiness
77
 
78
 
78
     public static function getSingle(array $scheduleType, StopsLiteRoutesLiteDbo $stop, Carbon $date, int $count)
79
     public static function getSingle(array $scheduleType, StopsLiteRoutesLiteDbo $stop, Carbon $date, int $count)
79
     {
80
     {
80
-        $data = static::getDataAccess()->get($scheduleType["resourceId"], "allweek", $stop->getStopId(), $stop->getRouteId());
81
+        $dbo = new StopsSchedulesDbo();
82
+        $dbo->setRouteId($stop->getRouteId());
83
+        $dbo->setStopId($stop->getStopId());
84
+        try {
85
+            $data = static::getDataAccess()->get($scheduleType["resourceId"], "allweek", $stop->getStopId(), $stop->getRouteId());
86
+        }
87
+        catch (ClientException $e) {
88
+            if ($e->getCode() == 404) {
89
+                $dbo->setSchedules([]);
90
+                return $dbo;
91
+            }
92
+            else {
93
+                throw $e;
94
+            }
95
+        }
81
         $schedules = static::getSchedulesForDate($data["data"]["schedules"], $date);
96
         $schedules = static::getSchedulesForDate($data["data"]["schedules"], $date);
82
 
97
 
83
         $schedulesCarbon = [];
98
         $schedulesCarbon = [];
89
             }
104
             }
90
         }
105
         }
91
 
106
 
92
-        $dbo = new StopsSchedulesDbo();
93
-        $dbo->setRouteId($stop->getRouteId());
94
-        $dbo->setStopId($stop->getStopId());
95
         $dbo->setSchedules($schedulesCarbon);
107
         $dbo->setSchedules($schedulesCarbon);
96
         return $dbo;
108
         return $dbo;
97
     }
109
     }

Loading…
Cancel
Save