From 8584b8cbf7ce34f11fc2d8c6c31cf8922ddb97b4 Mon Sep 17 00:00:00 2001 From: serguitus Date: Thu, 5 Jun 2014 12:44:28 -0400 Subject: [PATCH 1/2] 1690 raising exceptions for non-200 responses --- lib/doofinder_api.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/doofinder_api.php b/lib/doofinder_api.php index 697e6d1..0ba26fb 100644 --- a/lib/doofinder_api.php +++ b/lib/doofinder_api.php @@ -113,11 +113,27 @@ private function apiCall($params){ if (floor($httpCode / 100) == 2) { return new DoofinderResults($response); } + if ($httpCode == 403){ + // Access forbidden for that IP. + throw new DoofinderException($response, $httpCode); + } + if ($httpCode == 404){ + // SearchEngine or Index Not Found + throw new DoofinderException($response, $httpCode); + } + if ($httpCode == 413){ + // That Query is too long. + throw new DoofinderException("Query too large", $httpCode); + } if ($httpCode == 429){ // Query limit reached - throw new DoofinderException("Requests Limit Reached"); + throw new DoofinderException("Requests Limit Reached", $httpCode); + } + if ($httpCode == 500){ + // General Server Error + throw new DoofinderException($response, $httpCode); } - throw new DoofinderException($response); + throw new DoofinderException($httpCode.' '.$response, $httpCode); } /** From 0f61021c628cb4e576ca573eac7f55f7b52c9427 Mon Sep 17 00:00:00 2001 From: serguitus Date: Thu, 5 Jun 2014 13:07:30 -0400 Subject: [PATCH 2/2] 1690 just add the status Code --- lib/doofinder_api.php | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/lib/doofinder_api.php b/lib/doofinder_api.php index 0ba26fb..b38aafd 100644 --- a/lib/doofinder_api.php +++ b/lib/doofinder_api.php @@ -113,27 +113,7 @@ private function apiCall($params){ if (floor($httpCode / 100) == 2) { return new DoofinderResults($response); } - if ($httpCode == 403){ - // Access forbidden for that IP. - throw new DoofinderException($response, $httpCode); - } - if ($httpCode == 404){ - // SearchEngine or Index Not Found - throw new DoofinderException($response, $httpCode); - } - if ($httpCode == 413){ - // That Query is too long. - throw new DoofinderException("Query too large", $httpCode); - } - if ($httpCode == 429){ - // Query limit reached - throw new DoofinderException("Requests Limit Reached", $httpCode); - } - if ($httpCode == 500){ - // General Server Error - throw new DoofinderException($response, $httpCode); - } - throw new DoofinderException($httpCode.' '.$response, $httpCode); + throw new DoofinderException($httpCode.' - '.$response, $httpCode); } /**