From 4fa0bea2fcfe326f165952288cae7409ee4500d8 Mon Sep 17 00:00:00 2001 From: Atef Ben Ali Date: Mon, 22 May 2017 17:52:34 +0100 Subject: [PATCH] wrap code with try catch wrap code that may throw exception with try catch. --- src/Bing/Client.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Bing/Client.php b/src/Bing/Client.php index 7ad8f05..9da6979 100644 --- a/src/Bing/Client.php +++ b/src/Bing/Client.php @@ -26,12 +26,17 @@ public function __construct($api_key, $output = 'json') public function get($endpoint, $params = array()) { - $qs = "?\$format={$this->output}"; - if ($params['Query']) { - $params['Query'] = "'{$params['Query']}'"; - } - $qs .= ($params) ? '&'.http_build_query($params) : ''; + try { + $qs = "?\$format={$this->output}"; + if ($params['Query']) { + $params['Query'] = "'{$params['Query']}'"; + } + $qs .= ($params) ? '&'.http_build_query($params) : ''; - return file_get_contents($this->base_uri.'/'.$endpoint.$qs, 0, $this->context); + return file_get_contents($this->base_uri.'/'.$endpoint.$qs, 0, $this->context); + } catch(Exception $e) { + echo $e->getMessage(); + exit; + } } }