Skip to content

Commit

Permalink
Catch for trying to get instance or instance data from not existing i…
Browse files Browse the repository at this point in the history
…nstance
  • Loading branch information
alexmorbo committed Feb 8, 2023
1 parent 0a37bd8 commit a7bda3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Controller/InstanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,17 @@ function (Instance $instance) use ($channelId, $streamType) {
}
}
}

throw new TrassirException('Channel not found');
}
)
->then(
function ($video) use ($response) {
$response->getBody()->write($video);
return $response;
},
function (TrassirException $e) {
return new JsonResponse(['error' => $e->getMessage()], 404);
}
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/TrassirHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use AlexMorbo\Trassir\ConnectionOptions;
use AlexMorbo\Trassir\Dto\Server;
use AlexMorbo\Trassir\Trassir;
use AlexMorbo\Trassir\TrassirException;
use Clue\React\SQLite\DatabaseInterface;
use Psr\Log\LoggerInterface;
use React\Promise\PromiseInterface;
Expand Down Expand Up @@ -37,6 +38,10 @@ public function connectByInstanceId(int $instanceId): PromiseInterface
return $this->dbSearch('instances', ['id' => $instanceId])
->then(
function ($result) {
if (empty($result)) {
throw new TrassirException('Instance not found');
}

$this->instances[$result[0]['id']] = new Instance(
$result[0], $this->getTrassirInstance($result[0])
);
Expand Down

0 comments on commit a7bda3a

Please sign in to comment.