forked from lolcat/4get
1
0
Fork 0

Compare commits

..

No commits in common. "12d5b4ade817ef9512662e0a65c6850497566a33" and "c422abbdc65329e4f3a8eccdeac2a2e560cdff03" have entirely different histories.

1 changed files with 29 additions and 33 deletions

View File

@ -353,16 +353,25 @@ class qwant{
"related" => []
];
if(
$json["status"] != "success" &&
$json["data"]["error_code"] === 5
){
if($json["status"] != "success"){
if($json["data"]["error_code"] === 5){
// no results
return $out;
}
$this->detect_errors($json);
if(isset($json["data"]["error_code"])){
switch($json["data"]["error_code"]){
case 27:
throw new Exception("Qwant returned a captcha");
break;
}
}
throw new Exception("Qwant returned an error code: " . $json["data"]["error_code"]);
}
if(!isset($json["data"]["result"]["items"]["mainline"])){
@ -645,7 +654,10 @@ class qwant{
throw new Exception("Failed to decode JSON");
}
$this->detect_errors($json);
if($json["status"] != "success"){
throw new Exception("Qwant returned an API error");
}
if(isset($json["data"]["result"]["items"]["mainline"])){
@ -742,7 +754,10 @@ class qwant{
throw new Exception("Could not parse JSON");
}
$this->detect_errors($json);
if($json["status"] != "success"){
throw new Exception("Qwant returned an API error");
}
if(isset($json["data"]["result"]["items"]["mainline"])){
@ -846,7 +861,10 @@ class qwant{
throw new Exception("Could not parse JSON");
}
$this->detect_errors($json);
if($json["status"] != "success"){
throw new Exception("Qwant returned an API error");
}
if(isset($json["data"]["result"]["items"]["mainline"])){
@ -888,28 +906,6 @@ class qwant{
return $out;
}
private function detect_errors($json){
if(
isset($json["status"]) &&
$json["status"] == "error"
){
if(isset($json["data"]["error_data"]["captchaUrl"])){
throw new Exception("Qwant returned a captcha");
}elseif(isset($json["data"]["error_data"]["error_code"])){
throw new Exception(
"Qwant returned an API error: " .
$json["data"]["error_data"]["error_code"]
);
}
throw new Exception("Qwant returned an API error");
}
}
private function limitstrlen($text){
return explode("\n", wordwrap($text, 300, "\n"))[0];