Skip to content

Commit

Permalink
More robust error check from API
Browse files Browse the repository at this point in the history
  • Loading branch information
claudioc committed Mar 11, 2015
1 parent 5981ee9 commit e3339db
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ffexp.php
Expand Up @@ -189,6 +189,7 @@
$pages = 0;

$end_export = false;
$export_started = false;

fwrite($fh_tmp, "[\n");

Expand All @@ -201,6 +202,17 @@
$url = "https://friendfeed-api.com/v2/feed/{$stream}?" . http_build_query($qs);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);

if ($response === false || curl_errno($ch)) {

// We got a problem from the API, but the export was already start.
// Save what we have and say goodbye
if ($export_started) {
notify("We got a problem from the API. Maybe we reached the limit. The file is saved anyway.\n");
break;
}
}

$pages ++;

$data = json_decode($response);
Expand All @@ -211,7 +223,7 @@
@unlink($file_tmp);
exit;
}

$export_started = true;
$entries = array();
foreach ($data->entries as $entry) {

Expand Down

0 comments on commit e3339db

Please sign in to comment.