Skip to content

Commit e272998

Browse files
Log 404 instead of crashing crawler when APP_DEBUG = true
1 parent 8d4fe5b commit e272998

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"pestphp/pest": "^2.0",
3636
"pestphp/pest-plugin-arch": "^2.0",
3737
"pestphp/pest-plugin-laravel": "^2.0",
38+
"spatie/laravel-export": "^1.1",
3839
"spatie/laravel-ray": "^1.26"
3940
},
4041
"autoload": {

src/Deploy/Crawler/Observer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Code16\OzuClient\Deploy\Crawler;
44

5+
use Log;
56
use Psr\Http\Message\ResponseInterface;
67
use Psr\Http\Message\UriInterface;
78
use Spatie\Export\Crawler\Observer as BaseObserver;
@@ -13,7 +14,14 @@ public function crawled(UriInterface $url, ResponseInterface $response, ?UriInte
1314
try {
1415
parent::crawled($url, $response, $foundOnUrl, $linkText);
1516
} catch(\RuntimeException $e) {
16-
if(!app()->hasDebugModeEnabled() && preg_match('/returned status code \[4\d\d]/', $e->getMessage())) {
17+
if(preg_match('/returned status code \[4\d\d]/', $e->getMessage())) {
18+
Log::warning("Crawled URL {$url} found on {$foundOnUrl} returned status code 4xx", [
19+
'url' => (string) $url,
20+
'status_code' => $response->getStatusCode(),
21+
'found_on_url' => (string) $foundOnUrl,
22+
'link_text' => $linkText,
23+
]);
24+
1725
return;
1826
}
1927
throw $e;

0 commit comments

Comments
 (0)