Skip to content

Commit

Permalink
[Fix] Handle request exceptions (#49)
Browse files Browse the repository at this point in the history
* Throw exception when visiting fails

* Check if decoding content fixes "Unrecognized content encoding type"

* wip

* wip

* Fix styling

---------

Co-authored-by: Baspa <Baspa@users.noreply.github.com>
  • Loading branch information
Baspa and Baspa authored Oct 12, 2023
1 parent b217e4b commit 9805182
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 9805182

Please sign in to comment.