aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xservice.py31
-rw-r--r--session.py26
2 files changed, 36 insertions, 21 deletions
diff --git a/service.py b/service.py
index f1d1f4f..a8e999f 100755
--- a/service.py
+++ b/service.py
@@ -70,30 +70,39 @@ class RWAService(dbus.service.Object):
::
- {"status": "error"}
+ {"status": "error", "type": "<type>"}
+
+ **Possible choices for error types:** ``multiple``, ``connection``
"""
if ALLOW_ONLY_ONE_SESSION and len(self.sessions.values()) > 0:
logging.warning(
"There is already one session running and the service is configured to allow only one "
"session, so this session won't be started."
)
- return json.dumps({"status": "error"})
+ return json.dumps({"status": "error", "type": "multiple"})
# Start session
- session = Session(self.trigger_service.port, mockup_mode)
+ try:
+ session = Session(self.trigger_service.port, mockup_mode)
- # Add session to sessions list
- self.sessions[session.pid] = session
+ # Add session to sessions list
+ self.sessions[session.pid] = session
- # Start session update service
- self._ensure_update_service()
+ # Start session update service
+ self._ensure_update_service()
- return_json = session.client_meta
- return_json["status"] = "success"
+ return_json = session.client_meta
+ return_json["status"] = "success"
- logging.info(f"New session #{session.pid} was started with meta {return_json}.")
+ logging.info(
+ f"New session #{session.pid} was started with meta {return_json}."
+ )
+
+ return json.dumps(return_json)
+ except ConnectionError:
+ pass
- return json.dumps(return_json)
+ return json.dumps({"status": "error", "type": "connection"})
@dbus.service.method("org.ArcticaProject.RWA", in_signature="i", out_signature="s")
def status(self, pid: int) -> str:
diff --git a/session.py b/session.py
index 37cc312..e7ab922 100644
--- a/session.py
+++ b/session.py
@@ -107,21 +107,27 @@ class Session:
def _register_session(self):
"""Register session in RWA if not in mockup_session mode."""
if not self.mockup_session:
- r = requests.post(
- REGISTER_URL,
- json={
- "port": self.ws_port,
- "password": self.password,
- "pid": self.vnc_pid,
- "trigger_port": self.trigger_port,
- "trigger_token": self.trigger_token,
- },
- )
+ try:
+ r = requests.post(
+ REGISTER_URL,
+ json={
+ "port": self.ws_port,
+ "password": self.password,
+ "pid": self.vnc_pid,
+ "trigger_port": self.trigger_port,
+ "trigger_token": self.trigger_token,
+ },
+ )
+ except requests.exceptions.ConnectionError:
+ raise ConnectionError()
logging.info(
f"The session has been registered in RWA with status code {r.status_code} and response {r.content.decode()}."
)
+ if r.status_code != 200:
+ raise ConnectionError()
+
self.meta = r.json()
self.session_id = self.meta["session_id"]
self.web_url = self.meta["url"]