Skip to content

Commit efa1bb8

Browse files
committed
New hasBeenCrawled function with $error
1 parent 33c3ad2 commit efa1bb8

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/CrawlObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function willCrawl(Url $url);
2222
*
2323
* @return void
2424
*/
25-
public function hasBeenCrawled(Url $url, $response, Url $foundOnUrl = null);
25+
public function hasBeenCrawled(Url $url, $response, Url $foundOnUrl = null, $error = null);
2626

2727
/**
2828
* Called when the crawl has ended.

src/Crawler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ protected function startCrawlingQueue()
260260
'rejected' => function (RequestException $exception, int $index) {
261261
$this->handleResponse(
262262
$exception->getResponse(),
263-
$this->crawlQueue->getUrlById($index)
263+
$this->crawlQueue->getUrlById($index),
264+
$exception->getMessage() ?? null
264265
);
265266
},
266267
]);
@@ -274,9 +275,9 @@ protected function startCrawlingQueue()
274275
* @param ResponseInterface|null $response
275276
* @param CrawlUrl $crawlUrl
276277
*/
277-
protected function handleResponse($response, CrawlUrl $crawlUrl)
278+
protected function handleResponse($response, CrawlUrl $crawlUrl, $error = null)
278279
{
279-
$this->crawlObserver->hasBeenCrawled($crawlUrl->url, $response, $crawlUrl->foundOnUrl);
280+
$this->crawlObserver->hasBeenCrawled($crawlUrl->url, $response, $crawlUrl->foundOnUrl, $error);
280281
}
281282

282283
protected function getCrawlRequests(): Generator

src/EmptyCrawlObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function willCrawl(Url $url)
2424
*
2525
* @return void
2626
*/
27-
public function hasBeenCrawled(Url $url, $response, Url $foundOnUrl = null)
27+
public function hasBeenCrawled(Url $url, $response, Url $foundOnUrl = null, $error = null)
2828
{
2929
}
3030

0 commit comments

Comments
 (0)