diff --git a/src/Controller/InstanceController.php b/src/Controller/InstanceController.php index 76af439..37dff16 100644 --- a/src/Controller/InstanceController.php +++ b/src/Controller/InstanceController.php @@ -71,7 +71,7 @@ public function getInstance(ServerRequest $request, Response $response, string $ ->then( function ($result) use ($instanceId) { if (!$result) { - return new JsonResponse(['error' => 'Instance not found'], 404); + return new JsonResponse(['status' => 'error', 'error' => 'Instance not found'], 404); } return $this->trassirHelper->getInstance($instanceId) @@ -97,7 +97,7 @@ public function addInstance(ServerRequest $request, Response $response): Promise ) { $input = json_decode($request->getBody()->getContents(), true); if (json_last_error() !== JSON_ERROR_NONE) { - return resolve(new JsonResponse(['error' => 'Invalid JSON'], 400)); + return resolve(new JsonResponse(['status' => 'error', 'error' => 'Invalid JSON'], 400)); } } @@ -108,7 +108,7 @@ public function addInstance(ServerRequest $request, Response $response): Promise empty($input['login']) || empty($input['password']) ) { - return resolve(new JsonResponse(['error' => 'Invalid data'], 400)); + return resolve(new JsonResponse(['status' => 'error', 'error' => 'Invalid data'], 400)); } $instanceId = $this->dbInsert('instances', [ @@ -150,7 +150,7 @@ function() use ($instance, $instanceId) { ); }, function ($error) { - return new JsonResponse(['error' => $error]); + return new JsonResponse(['status' => 'error', 'error' => $error]); } ); } @@ -165,14 +165,14 @@ public function deleteInstance(ServerRequest $request, Response $response, $inpu function (int $deletedRows) { if ($deletedRows === 0) { return new JsonResponse( - ['error' => 'Instance not found'], StatusCodeInterface::STATUS_NOT_FOUND + ['status' => 'error', 'error' => 'Instance not found'], StatusCodeInterface::STATUS_NOT_FOUND ); } return new Response(StatusCodeInterface::STATUS_NO_CONTENT); }, function ($error) { - return new JsonResponse(['error' => $error]); + return new JsonResponse(['status' => 'error', 'error' => $error]); } ); } @@ -218,7 +218,7 @@ public function getChannelVideo( $instanceId = (int)$instanceId; if (!in_array($streamType, ['hls', 'rtsp'])) { - return resolve(new JsonResponse(['error' => 'Invalid stream type'], 400)); + return resolve(new JsonResponse(['status' => 'error', 'error' => 'Invalid stream type'], 400)); } return $this->trassirHelper->getInstance($instanceId) @@ -261,7 +261,7 @@ function ($video) use ($request, $response) { return $response; }, function (Exception $e) { - return new JsonResponse(['error' => $e->getMessage()], 404); + return new JsonResponse(['status' => 'error', 'error' => $e->getMessage()], 404); } ); } diff --git a/src/Server.php b/src/Server.php index ff99b2e..e92766a 100644 --- a/src/Server.php +++ b/src/Server.php @@ -131,7 +131,7 @@ private function initServer(string $ip, int $port): int $router ->map404("/(.*)", function () { - return resolve(new JsonResponse(['error' => 'Route not found'], 404)); + return resolve(new JsonResponse(['status' => 'error', 'error' => 'Route not found'], 404)); }) ->map500("/(.*)", function () { return resolve(new TextResponse("An internal error has occurred", 500));