From 9805182528ef65c22578b4e95d5e070585cc6398 Mon Sep 17 00:00:00 2001 From: Bas van Dinther Date: Thu, 12 Oct 2023 15:40:57 +0200 Subject: [PATCH] [Fix] Handle request exceptions (#49) * Throw exception when visiting fails * Check if decoding content fixes "Unrecognized content encoding type" * wip * wip * Fix styling --------- Co-authored-by: Baspa --- src/Seo.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Seo.php b/src/Seo.php index 85452024..2ccd5aaf 100755 --- a/src/Seo.php +++ b/src/Seo.php @@ -41,7 +41,7 @@ public function check(string $url, ProgressBar $progress = null, bool $useJavasc $javascriptResponse = $this->visitPageUsingJavascript(url: $url); } } catch (\Exception $e) { - return (new SeoScore)($this->successful, $this->failed); + throw new \Exception("Could not visit url `{$url}`: {$e->getMessage()}"); } $this->runChecks(response: $response, javascriptResponse: $javascriptResponse ?? null); @@ -62,7 +62,10 @@ private function visitPage(string $url): object $headers = (array) config('seo.http.headers', []); $options = (array) config('seo.http.options', []); - $response = $this->http::withOptions($options) + $response = $this->http::withOptions([ + 'decode_content' => false, + ...$options, + ]) ->withHeaders([ 'Accept-Encoding' => 'gzip, deflate', ...$headers,