Skip to content

Commit

Permalink
[#72] minor tweaks to error handling/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
j-h-s committed Jan 5, 2018
1 parent 6af50f7 commit ac55628
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/AppBundle/Command/ScraperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function scrapeFacebook($partyCode, $socialNetworks)
->getFBData($partyCode, $socialNetworks['facebook']['username'], $this->scrapeData, $this->scrapeFull);

if (!$fbData) {
$this->log->warning(" - ERROR while retrieving FB data for " . $partyCode);
$this->log->notice(" - ERROR while retrieving FB data for " . $partyCode);
return false;
}

Expand All @@ -171,7 +171,7 @@ public function scrapeTwitter($partyCode, $socialNetworks)
->getTwitterData($partyCode, $socialNetworks['twitter']['username'], $this->scrapeData, $this->scrapeFull);

if (!$twData) {
$this->log->warning(" - ERROR while retrieving Twitter data for " . $partyCode);
$this->log->notice(" - ERROR while retrieving Twitter data for " . $partyCode);
return false;
}

Expand All @@ -198,7 +198,7 @@ public function scrapeGooglePlus($partyCode, $socialNetworks)
->getGooglePlusData($partyCode, $socialNetworks['googlePlus']);

if (empty($gData)) {
$this->log->warning(" - ERROR while retrieving Google+ data for " . $partyCode);
$this->log->notice(" - ERROR while retrieving Google+ data for " . $partyCode);
return false;
}

Expand All @@ -224,7 +224,7 @@ public function scrapeYoutube($partyCode, $socialNetworks)
->getYoutubeData($partyCode, $socialNetworks['youtube'], $this->scrapeData);

if (!$ytData) {
$this->log->warning(" - ERROR while retrieving Youtube data for " . $partyCode);
$this->log->notice(" - ERROR while retrieving Youtube data for " . $partyCode);
return false;
}

Expand Down
21 changes: 10 additions & 11 deletions src/AppBundle/Service/ConnectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public function __construct(Container $container) {


public function exception_handler($e) {
$message = $e->getMessage();
$this->log->error($message);

if ($message == "Application request limit reached") {
$this->getFbRateLimit();
} else {
$message = $e->getMessage();
$this->log->error($message);
}
}


/**
* Builds a Facebook Throttle Exception to test error handling
* Throws a Facebook Throttle Exception to test error handling
*/
public function testFbRateLimit() {
$e = new FacebookThrottleException("Application request limit reached");
Expand Down Expand Up @@ -90,17 +90,14 @@ public function getFbGraphNode($fbPageId, $fields) {

} catch(Facebook\Exceptions\FacebookThrottleException $e) {
// When the app hits the rate limit
$this->log->error($fbPageId . " - " . $e->getMessage());
$response = $this->getFbRateLimit($request);

} catch(\Exception $e) {
$this->log->error($fbPageId . " - Exception: " . $e->getMessage());

if ($e->getMessage() == "Application request limit reached") {
$this->getFbRateLimit($request);

$response = $this->getFbRateLimit($request);
} else {
return false;
$this->log->error($fbPageId . " - Exception: " . $e->getMessage());
return false;
}
}

Expand All @@ -119,6 +116,8 @@ public function getFbGraphNode($fbPageId, $fields) {
public function getFbRateLimit($request = null) {
$connected = false;

$this->log->warning(" - Facebook rate limit reached!");

if (is_null($request)) {
$request = $this->fb->request('GET', $this->fbPageId, ['fields' => 'engagement']);
}
Expand Down Expand Up @@ -217,7 +216,7 @@ public function getTwRateLimit($tw) {
// $this->log->debug(" + (" . $limitCheck['remaining'] . " requests remaining, resetting at " . date('H:i:s', $limitCheck['reset']) . ") ");

if ($limitCheck['remaining'] < 2) { // give ourselves a little bit of wiggle room
$this->log->warning(" - Rate limit reached! Resuming at " . date('H:i:s', $limitCheck['reset']) . "...");
$this->log->notice(" - Twitter rate limit reached! Resuming at " . date('H:i:s', $limitCheck['reset']) . "...");
time_sleep_until($limitCheck['reset']);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/AppBundle/Service/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function saveImage($site, $code, $imgSrc, $imgId, $imgBkp = null) {
try {
$imgData = file_get_contents($imgSrc, false, $ctx);
} catch (\Exception $e) {
$this->log->warning($e->getMessage());
$this->log->notice($e->getMessage());
if ($imgBkp) { // try backup if available
try {
$imgData = file_get_contents($imgBkp, false, $ctx);
Expand All @@ -75,7 +75,7 @@ public function saveImage($site, $code, $imgSrc, $imgId, $imgBkp = null) {
try {
file_put_contents($imgPath, $imgData);
} catch (\Exception $e) {
$this->log->warning($e->getMessage());
$this->log->notice($e->getMessage());
}
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public function getFacebookCover($partyCode, $imgSrc) {
try {
$imgData = file_get_contents($imgSrc, false, $ctx);
} catch (\Exception $e) {
$this->log->warning($e->getMessage());
$this->log->notice($e->getMessage());
}

if (empty($imgData)) {
Expand Down

0 comments on commit ac55628

Please sign in to comment.