Skip to content

Commit

Permalink
Add an extra null check when a request fails to determine the message
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed May 22, 2018
1 parent e233871 commit 54c3102
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `spatie/http-status-check` will be documented in this file.

## 3.1.1 - 2018-05-22

- Add an extra null check when a request fails to determine the message.

## 3.1.0 - 2018-05-09

- Update crawler to `^4.1.0`.
Expand Down
12 changes: 7 additions & 5 deletions src/CrawlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public function crawled(

$timestamp = date('Y-m-d H:i:s');

$message = "{$statusCode} {$reason} - ".(string) $url;
$message = "{$statusCode} {$reason} - " . (string) $url;

if ($this->outputFile && $colorTag === 'error') {
file_put_contents($this->outputFile, $message.PHP_EOL, FILE_APPEND);
file_put_contents($this->outputFile, $message . PHP_EOL, FILE_APPEND);
}

$this->consoleOutput->writeln("<{$colorTag}>[{$timestamp}] {$message}</{$colorTag}>");
Expand All @@ -143,20 +143,22 @@ public function crawlFailed(
) {
$statusCode = self::UNRESPONSIVE_HOST;

$reason = $requestException->getResponse()->getReasonPhrase();
$reason = $requestException->getResponse()
? $requestException->getResponse()->getReasonPhrase()
: $requestException->getMessage();

$colorTag = $this->getColorTagForStatusCode($statusCode);

$timestamp = date('Y-m-d H:i:s');

$message = "{$statusCode}: {$reason} - ".(string) $url;
$message = "{$statusCode}: {$reason} - " . (string) $url;

if ($foundOnUrl) {
$message .= " (found on {$foundOnUrl})";
}

if ($this->outputFile) {
file_put_contents($this->outputFile, $message.PHP_EOL, FILE_APPEND);
file_put_contents($this->outputFile, $message . PHP_EOL, FILE_APPEND);
}

$this->consoleOutput->writeln("<{$colorTag}>[{$timestamp}] {$message}</{$colorTag}>");
Expand Down

0 comments on commit 54c3102

Please sign in to comment.