Ver código fonte

catch bad stop/route pair

tags/v1.0.0
Robin Thoni 8 anos atrás
pai
commit
ebbe33f1c9
1 arquivos alterados com 16 adições e 4 exclusões
  1. 16
    4
      app/Business/SchedulesBusiness.php

+ 16
- 4
app/Business/SchedulesBusiness.php Ver arquivo

@@ -14,6 +14,7 @@ use App\Dbo\StopsLiteRoutesLiteDbo;
14 14
 use App\Dbo\StopsLiteRoutesLiteDboArray;
15 15
 use App\Dbo\StopsSchedulesDbo;
16 16
 use Carbon\Carbon;
17
+use GuzzleHttp\Exception\ClientException;
17 18
 use Luticate\Utils\Dbo\LuPaginatedDbo;
18 19
 
19 20
 class SchedulesBusiness
@@ -77,7 +78,21 @@ class SchedulesBusiness
77 78
 
78 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 96
         $schedules = static::getSchedulesForDate($data["data"]["schedules"], $date);
82 97
 
83 98
         $schedulesCarbon = [];
@@ -89,9 +104,6 @@ class SchedulesBusiness
89 104
             }
90 105
         }
91 106
 
92
-        $dbo = new StopsSchedulesDbo();
93
-        $dbo->setRouteId($stop->getRouteId());
94
-        $dbo->setStopId($stop->getStopId());
95 107
         $dbo->setSchedules($schedulesCarbon);
96 108
         return $dbo;
97 109
     }

Carregando…
Cancelar
Salvar