Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 3149cca

Browse files
committed
Merge pull request repejota#53 from dfeyer/task-better-exception
TASK: Better exception handling in Connection::handleMSG
2 parents 39ee833 + 7a192f4 commit 3149cca

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/Connection.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ private function handlePING()
353353
*
354354
* @param string $line Message command from NATS.
355355
*
356-
* @return \Exception|void
356+
* @return void
357+
* @throws Exception
357358
* @codeCoverageIgnore
358359
*/
359360
private function handleMSG($line)
@@ -374,11 +375,15 @@ private function handleMSG($line)
374375
$payload = $this->receive($length);
375376
$msg = new Message($subject, $payload, $sid, $this);
376377

378+
if (!isset($this->subscriptions[$sid])) {
379+
throw new Exception('subscription not found');
380+
}
381+
377382
$func = $this->subscriptions[$sid];
378383
if (is_callable($func)) {
379384
$func($msg);
380385
} else {
381-
return new \Exception('not callable');
386+
throw new Exception('not callable');
382387
}
383388

384389
return;

src/Exception.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace Nats;
3+
4+
/**
5+
* Exception Class.
6+
*/
7+
class Exception extends \Exception
8+
{
9+
10+
}

0 commit comments

Comments
 (0)