Skip to content

Commit 247d4ec

Browse files
committed
Updated error handling. If the client couldn't connect to Unreal, the response was just "False", which was pretty bad. You now get a proper error string back
1 parent 68b2f8c commit 247d4ec

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

skyhook/client.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pprint
2+
from datetime import datetime
23

3-
from .constants import HostPrograms, Results, Ports, ServerCommands
4+
from .constants import HostPrograms, Results, Ports, ServerCommands, Errors
45
import requests
56

67
try:
@@ -91,7 +92,7 @@ def is_host_online(self):
9192
:return: *bool*
9293
"""
9394
response = self.execute("is_online", {})
94-
return response.get(Results.return_value)
95+
return response.get(Results.return_value) is True
9596

9697

9798
def execute(self, command, parameters={}, timeout=0):
@@ -127,7 +128,21 @@ def execute(self, command, parameters={}, timeout=0):
127128

128129
url = "http://%s:%s" % (self.host_address, self.port)
129130
payload = self.__create_payload(command, parameters)
130-
response = requests.post(url, json=payload, timeout=timeout).json()
131+
132+
133+
# set the response dictionary to be NO_RESPONSE
134+
response = {
135+
Results.time: datetime.now().strftime("%H:%M:%S"),
136+
Results.success: False,
137+
Results.return_value: Errors.NO_RESPONSE,
138+
Results.command: command
139+
}
140+
141+
try:
142+
# the response
143+
response = requests.post(url, json=payload, timeout=timeout).json()
144+
except requests.exceptions.ConnectionError as err:
145+
response[Results.return_value] = "\n".join([Errors.CANT_REACH_SERVER, str(err)])
131146

132147
if self.echo_payload():
133148
pprint.pprint(payload)
@@ -235,7 +250,7 @@ def execute(self, command, parameters={}, timeout=0, function=True, property=Fal
235250
try:
236251
response = requests.put(url, json=payload, headers=self.__headers, timeout=timeout).json()
237252
except requests.exceptions.ConnectionError:
238-
response = {"ReturnValue": False}
253+
response = {Results.return_value: Errors.CANT_REACH_SERVER}
239254

240255
try:
241256
# UE 4.26: Returning an unreal.Array() that's not empty crashes the editor

skyhook/constants.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ class Errors:
5757
"""
5858
Errors when things go wrong
5959
"""
60-
CALLING_FUNCTION = "An error occurred when calling the function"
61-
IN_FUNCTION = "An error occurred when executing the function"
62-
SERVER_COMMAND = "An error occurred processing this server command"
63-
SERVER_RELOAD = "An error occurred with reloading a module on the server"
64-
TIMEOUT = "The command timed out"
60+
CALLING_FUNCTION = "ERROR 0x1: An error occurred when calling the function"
61+
IN_FUNCTION = "ERROR 0x2: An error occurred when executing the function"
62+
SERVER_COMMAND = "ERROR 0x3: An error occurred processing this server command"
63+
SERVER_RELOAD = "ERROR 0x4: An error occurred with reloading a module on the server"
64+
TIMEOUT = "ERROR 0x5: The command timed out"
65+
CANT_REACH_SERVER = "ERROR 0x6: The client couldn't connect to the server"
66+
NO_RESPONSE = "ERROR 0x7: No response was generated, is the function on the server returning anything?"
6567

6668

6769
class UnrealTypes:

0 commit comments

Comments
 (0)