From 17cb5e8bec950b8df6382d9d37ea92f5084ddeab Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 1 Nov 2015 12:05:07 +0100 Subject: [PATCH] Intercept error in connecting to the GPM and tell "Cannot connect to the GPM" instead of "Internal Server Error" --- admin.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/admin.php b/admin.php index c605d075..42bac55b 100644 --- a/admin.php +++ b/admin.php @@ -294,19 +294,23 @@ class AdminPlugin extends Plugin switch ($action) { case 'getUpdates': $resources_updates = $gpm->getUpdatable(); - $grav_updates = [ - "isUpdatable" => $gpm->grav->isUpdatable(), - "assets" => $gpm->grav->getAssets(), - "version" => GRAV_VERSION, - "available" => $gpm->grav->getVersion(), - "date" => $gpm->grav->getDate(), - "isSymlink" => $gpm->grav->isSymlink() - ]; + if ($gpm->grav != null) { + $grav_updates = [ + "isUpdatable" => $gpm->grav->isUpdatable(), + "assets" => $gpm->grav->getAssets(), + "version" => GRAV_VERSION, + "available" => $gpm->grav->getVersion(), + "date" => $gpm->grav->getDate(), + "isSymlink" => $gpm->grav->isSymlink() + ]; - echo json_encode([ - "status" => "success", - "payload" => ["resources" => $resources_updates, "grav" => $grav_updates, "installed" => $gpm->countInstalled(), 'flushed' => $flush] - ]); + echo json_encode([ + "status" => "success", + "payload" => ["resources" => $resources_updates, "grav" => $grav_updates, "installed" => $gpm->countInstalled(), 'flushed' => $flush] + ]); + } else { + echo json_encode(["status" => "error", "message" => "Cannot connect to the GPM"]); + } break; } } catch (\Exception $e) {