diff --git a/src/Facebook/FacebookClient.php b/src/Facebook/FacebookClient.php index dbf759238..175abd602 100644 --- a/src/Facebook/FacebookClient.php +++ b/src/Facebook/FacebookClient.php @@ -23,6 +23,7 @@ */ namespace Facebook; +use Facebook\Exceptions\FacebookResponseException; use Facebook\HttpClients\FacebookHttpClientInterface; use Facebook\HttpClients\FacebookCurlHttpClient; use Facebook\HttpClients\FacebookStreamHttpClient; @@ -192,7 +193,7 @@ public function prepareRequestMessage(FacebookRequest $request) * @param FacebookRequest $request * * @return FacebookResponse - * + * @throws FacebookResponseException * @throws FacebookSDKException */ public function sendRequest(FacebookRequest $request) diff --git a/src/Facebook/FileUpload/FacebookResumableUploader.php b/src/Facebook/FileUpload/FacebookResumableUploader.php index 46a2727b9..a5fa1b09c 100644 --- a/src/Facebook/FileUpload/FacebookResumableUploader.php +++ b/src/Facebook/FileUpload/FacebookResumableUploader.php @@ -103,6 +103,7 @@ public function start($endpoint, FacebookFile $file) * @return FacebookTransferChunk * * @throws FacebookResponseException + * @throws FacebookSDKException */ public function transfer($endpoint, FacebookTransferChunk $chunk, $allowToThrow = false) { @@ -132,6 +133,12 @@ public function transfer($endpoint, FacebookTransferChunk $chunk, $allowToThrow } // Return the same chunk entity so it can be retried. + return $chunk; + } catch (FacebookSDKException $e) { + if ($allowToThrow) { + throw $e; + } + return $chunk; } @@ -167,6 +174,8 @@ public function finish($endpoint, $uploadSessionId, $metadata = []) * @param array $params The params to send with the request. * * @return array + * @throws FacebookResponseException + * @throws FacebookSDKException */ private function sendUploadRequest($endpoint, $params = []) { diff --git a/tests/FileUpload/FacebookResumableUploaderTest.php b/tests/FileUpload/FacebookResumableUploaderTest.php index dfdbe6f41..bac634f6f 100644 --- a/tests/FileUpload/FacebookResumableUploaderTest.php +++ b/tests/FileUpload/FacebookResumableUploaderTest.php @@ -109,4 +109,14 @@ public function testFailedResumableTransferWillNotThrowAndReturnNewChunk() $this->assertEquals(40, $newChunk->getStartOffset()); $this->assertEquals(50, $newChunk->getEndOffset()); } + + public function testFailedClientRequestWillNotThrowAndReturnSameChunk() + { + $this->graphApi->failOnClientRequest(); + $uploader = new FacebookResumableUploader($this->fbApp, $this->client, 'access_token', 'v2.4'); + + $chunk = new FacebookTransferChunk($this->file, '1', '2', '3', '4'); + $newChunk = $uploader->transfer('/me/videos', $chunk); + $this->assertSame($newChunk, $chunk); + } } diff --git a/tests/Fixtures/FakeGraphApiForResumableUpload.php b/tests/Fixtures/FakeGraphApiForResumableUpload.php index 29f56446c..b20696bb1 100644 --- a/tests/Fixtures/FakeGraphApiForResumableUpload.php +++ b/tests/Fixtures/FakeGraphApiForResumableUpload.php @@ -24,6 +24,7 @@ namespace Facebook\Tests\Fixtures; +use Facebook\Exceptions\FacebookSDKException; use Facebook\Http\GraphRawResponse; use Facebook\HttpClients\FacebookHttpClientInterface; @@ -42,6 +43,11 @@ public function failOnTransfer() $this->respondWith = 'FAIL_ON_TRANSFER'; } + public function failOnClientRequest() + { + $this->respondWith = 'FAIL_ON_CLIENT_REQUEST'; + } + public function failOnTransferAndUploadNewChunk() { $this->respondWith = 'FAIL_ON_TRANSFER_AND_UPLOAD_NEW_CHUNK'; @@ -95,6 +101,10 @@ private function respondTransfer() ); } + if ($this->respondWith == 'FAIL_ON_CLIENT_REQUEST') { + throw new FacebookSDKException("SSL_write() returned SYSCALL, errno = 104", 55); + } + switch ($this->transferCount) { case 0: $data = ['start_offset' => 20, 'end_offset' => 40];