diff --git a/app/Traits/Modules.php b/app/Traits/Modules.php index 3d08e4332..446f9267d 100644 --- a/app/Traits/Modules.php +++ b/app/Traits/Modules.php @@ -6,6 +6,7 @@ use App\Utilities\Info; use Artisan; use File; use GuzzleHttp\Client; +use GuzzleHttp\Exception\RequestException; use Module; use ZipArchive; @@ -22,7 +23,7 @@ trait Modules $response = $this->getRemote('token/check', 'POST', $data); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { $result = json_decode($response->getBody()); return ($result->success) ? true : false; @@ -35,7 +36,7 @@ trait Modules { $response = $this->getRemote('apps/items'); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return json_decode($response->getBody())->data; } @@ -46,7 +47,7 @@ trait Modules { $response = $this->getRemote('apps/' . $alias); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return json_decode($response->getBody())->data; } @@ -57,7 +58,7 @@ trait Modules { $response = $this->getRemote('apps/categories'); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return json_decode($response->getBody())->data; } @@ -68,7 +69,7 @@ trait Modules { $response = $this->getRemote('apps/categories/' . $alias); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return json_decode($response->getBody())->data; } @@ -79,7 +80,7 @@ trait Modules { $response = $this->getRemote('apps/paid', 'GET', $data); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return json_decode($response->getBody())->data; } @@ -90,7 +91,7 @@ trait Modules { $response = $this->getRemote('apps/new', 'GET', $data); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return json_decode($response->getBody())->data; } @@ -101,7 +102,7 @@ trait Modules { $response = $this->getRemote('apps/free', 'GET', $data); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return json_decode($response->getBody())->data; } @@ -112,7 +113,7 @@ trait Modules { $response = $this->getRemote('apps/search', 'GET', $data); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return json_decode($response->getBody())->data; } @@ -125,7 +126,7 @@ trait Modules $response = $this->getRemote('core/version', 'GET', $data); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { return $response->json(); } @@ -136,7 +137,7 @@ trait Modules { $response = $this->getRemote($path); - if ($response->getStatusCode() == 200) { + if ($response && ($response->getStatusCode() == 200)) { $file = $response->getBody()->getContents(); $path = 'temp-' . md5(mt_rand()); @@ -327,7 +328,11 @@ trait Modules $data = array_merge($data, $headers); - $result = $client->request($method, $path, $data); + try { + $result = $client->request($method, $path, $data); + } catch (RequestException $e) { + $result = false; + } return $result; } diff --git a/app/Traits/SiteApi.php b/app/Traits/SiteApi.php index 172cd24bf..1f178edd4 100644 --- a/app/Traits/SiteApi.php +++ b/app/Traits/SiteApi.php @@ -3,6 +3,7 @@ namespace App\Traits; use GuzzleHttp\Client; +use GuzzleHttp\Exception\RequestException; trait SiteApi { @@ -23,7 +24,11 @@ trait SiteApi $data = array_merge($data, $headers); - $result = $client->get($url, $data); + try { + $result = $client->get($url, $data); + } catch (RequestException $e) { + $result = $e; + } return $result; } diff --git a/app/Utilities/Updater.php b/app/Utilities/Updater.php index a7a8a3fcc..e0f6c220f 100644 --- a/app/Utilities/Updater.php +++ b/app/Utilities/Updater.php @@ -10,6 +10,7 @@ use Date; use File; use Module; use ZipArchive; +use GuzzleHttp\Exception\RequestException; class Updater { @@ -107,6 +108,11 @@ class Updater $response = static::getRemote($url, ['timeout' => 30, 'track_redirects' => true]); + // Exception + if ($response instanceof RequestException) { + return false; + } + if ($response->getStatusCode() == 200) { $file = $response->getBody()->getContents(); } diff --git a/app/Utilities/Versions.php b/app/Utilities/Versions.php index f82f7ef46..cec530fdf 100644 --- a/app/Utilities/Versions.php +++ b/app/Utilities/Versions.php @@ -6,6 +6,7 @@ use App\Traits\SiteApi; use Cache; use Date; use Parsedown; +use GuzzleHttp\Exception\RequestException; class Versions { @@ -90,7 +91,12 @@ class Versions { $latest = '0.0.0'; - $response = static::getRemote($url, ['timeout' => 30, 'referer' => true]); + $response = static::getRemote($url, ['timeout' => 1, 'referer' => true]); + + // Exception + if ($response instanceof RequestException) { + return $latest; + } // Bad response if ($response->getStatusCode() != 200) {