Skip to content

Commit 58cf5d6

Browse files
authored
Merge pull request #70 from RageZBla/67-handle-404-gracefully
Try to process the page even when the server returned 4xx or 5xxx.
2 parents 23d8852 + 40f3c1d commit 58cf5d6

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/OpenGraph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function curl_get_contents($url, $lang, $userAgent)
7070

7171
curl_setopt_array($curl, [
7272
CURLOPT_URL => $url,
73-
CURLOPT_FAILONERROR => true,
73+
CURLOPT_FAILONERROR => false,
7474
CURLOPT_FOLLOWLOCATION => true,
7575
CURLOPT_RETURNTRANSFER => true,
7676
CURLOPT_SSL_VERIFYHOST => false,

tests/OpenGraphTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadata()
4848
$this->assertEmpty($data);
4949
}
5050

51+
/** @test */
52+
public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadataAndReturnedNotFound()
53+
{
54+
$opengraph = new OpenGraph();
55+
$data = $opengraph->fetch(
56+
'https://www.example.com/not-found'
57+
);
58+
59+
$this->assertEmpty($data);
60+
}
61+
5162
/** @test */
5263
public function testFetchMustacheMetasData()
5364
{

0 commit comments

Comments
 (0)