diff --git a/src/Torrentio/Client/Torrentio.php b/src/Torrentio/Client/Torrentio.php index eb50c5e..109012f 100644 --- a/src/Torrentio/Client/Torrentio.php +++ b/src/Torrentio/Client/Torrentio.php @@ -38,11 +38,21 @@ class Torrentio $results = $this->cache->get($cacheKey, function (ItemInterface $item) use ($imdbCode) { $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0)); - $response = file_get_contents(str_replace('{imdbCode}', $imdbCode, $this->searchUrl)); - return json_decode( - $response, - true - ); + try { + $response = $this->client->get("$this->searchUrl/$imdbCode.json"); + return json_decode( + $response->getBody()->getContents(), + true + ); + } catch (\Throwable $exception) { + if ($exception->getCode() === 429) { + $this->logger->warning("> [TorrentioClient] Rate limit exceeded"); + return null; + } + } + + $this->logger->error("> [TorrentioClient] Request error: " . $response->getStatusCode() . " - " . $response->getBody()->getContents()); + return []; }); return $this->parse($results, $filter);