diff --git a/src/RpcClient.php b/src/RpcClient.php index 2870fb4..26e890f 100644 --- a/src/RpcClient.php +++ b/src/RpcClient.php @@ -530,6 +530,7 @@ private function buildRequestBody($method, array $arguments = []) * @param string $requestBody * @return array * @throws CSRFException + * @throws DuplicateTorrentException * @throws TransmissionException */ private function sendRequest($sessionId, $requestBody) @@ -599,6 +600,16 @@ private function sendRequest($sessionId, $requestBody) throw $e; } + if (isset($responseBody['arguments']['torrent-duplicate'])) { + $torrentDuplicateData = $responseBody['arguments']['torrent-duplicate']; + $e = new DuplicateTorrentException(); + $e->setTorrentId($torrentDuplicateData['id']); + $e->setTorrentName($torrentDuplicateData['name']); + $e->setTorrentHashString($torrentDuplicateData['hashString']); + + throw $e; + } + return $responseBody; } } diff --git a/tests/RpcClientTest.php b/tests/RpcClientTest.php index b829708..429c210 100644 --- a/tests/RpcClientTest.php +++ b/tests/RpcClientTest.php @@ -716,7 +716,7 @@ public function testTorrentAddShouldThrowAnExceptionWithDuplicateTorrent() ->andReturn($this->guzzleResponse); $this->setResponseBody(sprintf( - '{"arguments":{"torrent-duplicate":{"id":%d,"name":"%s","hashString":"%s"}},"result":"duplicate torrent"}', + '{"arguments":{"torrent-duplicate":{"id":%d,"name":"%s","hashString":"%s"}},"result":"success"}', $torrentId, $torrentName, $hashString