Skip to content

Commit

Permalink
Catch PhantomJS exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Jan 25, 2017
1 parent 97bbc55 commit 657f048
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions app/Models/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -1193,21 +1193,27 @@ public function getPDFString()

$invitation = $this->invitations[0];
$link = $invitation->getLink('view', true);

if (env('PHANTOMJS_BIN_PATH')) {
$pdfString = CurlUtils::phantom('GET', $link . '?phantomjs=true');
} elseif ($key = env('PHANTOMJS_CLOUD_KEY')) {
if (Utils::isNinjaDev()) {
$link = env('TEST_LINK');
$pdfString = false;

try {
if (env('PHANTOMJS_BIN_PATH')) {
$pdfString = CurlUtils::phantom('GET', $link . '?phantomjs=true');
} elseif ($key = env('PHANTOMJS_CLOUD_KEY')) {
if (Utils::isNinjaDev()) {
$link = env('TEST_LINK');
}
$url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%22,renderType:%22html%22%7D";
$pdfString = CurlUtils::get($url);
}
$url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%22,renderType:%22html%22%7D";
$pdfString = CurlUtils::get($url);
}

$pdfString = strip_tags($pdfString);
$pdfString = strip_tags($pdfString);
} catch (Exception $exception) {
Utils::logError("PhantomJS - Failed to create pdf: {$exception->getMessage()}");
return false;
}

if ( ! $pdfString || strlen($pdfString) < 200) {
Utils::logError("PhantomJSCloud - failed to create pdf: {$pdfString}");
Utils::logError("PhantomJS - Failed to create pdf: {$pdfString}");
return false;
}

Expand Down

0 comments on commit 657f048

Please sign in to comment.