From c2a7d8ff8ed3415c32e974fd07b7000d7564243e Mon Sep 17 00:00:00 2001 From: Helge Sverre Date: Thu, 12 Dec 2019 14:50:10 +0100 Subject: [PATCH] Hotfix, admin crash if api key is wrong or invalid --- src/HubspotConnector.php | 20 ++++++++++++-------- src/services/Hubspot.php | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/HubspotConnector.php b/src/HubspotConnector.php index 4d56bee..51446d5 100644 --- a/src/HubspotConnector.php +++ b/src/HubspotConnector.php @@ -111,17 +111,21 @@ protected function getFrequencyList() protected function getContactInformationPropertiesList() { - - if ($this->hubspot->hasApiKey() === false) { return []; } - return array_map(function ($item) { - return [ - "label" => $item->label, - "value" => $item->name, - ]; - }, $this->hubspot->getHubspotDefinedContactInformationProperties()); + try { + + return array_map(function ($item) { + return [ + "label" => $item->label, + "value" => $item->name, + ]; + }, $this->hubspot->getHubspotDefinedContactInformationProperties()); + } catch (\Exception $e) { + // Prevent admin area from crashing if the api key is wrong + return []; + } } } diff --git a/src/services/Hubspot.php b/src/services/Hubspot.php index d21c148..5ae24dd 100644 --- a/src/services/Hubspot.php +++ b/src/services/Hubspot.php @@ -86,7 +86,7 @@ protected function setupClients() public function hasApiKey() { - return empty($this->apiKey) === false; + return trim($this->apiKey) != ""; }