summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ogRest.py55
1 files changed, 23 insertions, 32 deletions
diff --git a/src/ogRest.py b/src/ogRest.py
index 69620e6..fe6c0da 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -87,10 +87,8 @@ class ogThread():
try:
shellout = ogRest.operations.shellrun(request, ogRest)
- except ValueError as err:
- response = restResponse(ogResponses.INTERNAL_ERR)
- client.send(response.get())
- ogRest.state = ThreadState.IDLE
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
return
if request.getEcho():
@@ -114,10 +112,8 @@ class ogThread():
def session(client, request, ogRest):
try:
ogRest.operations.session(request, ogRest)
- except ValueError as err:
- response = restResponse(ogResponses.INTERNAL_ERR)
- client.send(response.get())
- ogRest.state = ThreadState.IDLE
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
return
response = restResponse(ogResponses.OK)
@@ -127,10 +123,8 @@ class ogThread():
def software(client, request, path, ogRest):
try:
software = ogRest.operations.software(request, path, ogRest)
- except ValueError as err:
- response = restResponse(ogResponses.INTERNAL_ERR)
- client.send(response.get())
- ogRest.state = ThreadState.IDLE
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
return
json_body = jsonBody()
@@ -144,10 +138,8 @@ class ogThread():
def hardware(client, path, ogRest):
try:
ogRest.operations.hardware(path, ogRest)
- except ValueError as err:
- response = restResponse(ogResponses.INTERNAL_ERR)
- client.send(response.get())
- ogRest.state = ThreadState.IDLE
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
return
json_body = jsonBody()
@@ -161,10 +153,8 @@ class ogThread():
def setup(client, request, ogRest):
try:
out = ogRest.operations.setup(request, ogRest)
- except ValueError as err:
- response = restResponse(ogResponses.INTERNAL_ERR)
- client.send(response.get())
- ogRest.state = ThreadState.IDLE
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
return
json_body = jsonBody(out)
@@ -176,10 +166,8 @@ class ogThread():
def image_restore(client, request, ogRest):
try:
ogRest.operations.image_restore(request, ogRest)
- except ValueError as err:
- response = restResponse(ogResponses.INTERNAL_ERR)
- client.send(response.get())
- ogRest.state = ThreadState.IDLE
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
return
json_body = jsonBody()
@@ -197,10 +185,8 @@ class ogThread():
request,
ogRest)
software = ogRest.operations.software(request, path, ogRest)
- except ValueError as err:
- response = restResponse(ogResponses.INTERNAL_ERR)
- client.send(response.get())
- ogRest.state = ThreadState.IDLE
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
return
kibi = 1024
@@ -226,10 +212,8 @@ class ogThread():
def refresh(client, ogRest):
try:
out = ogRest.operations.refresh(ogRest)
- except ValueError as err:
- response = restResponse(ogResponses.INTERNAL_ERR)
- client.send(response.get())
- ogRest.state = ThreadState.IDLE
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
return
json_body = jsonBody(out)
@@ -276,6 +260,13 @@ class ogRest():
else:
raise ValueError('Mode not supported.')
+ def send_internal_server_error(self, client, exc=None):
+ if exc:
+ logging.exception('Unexpected error')
+ response = restResponse(ogResponses.INTERNAL_ERR)
+ client.send(response.get())
+ self.state = ThreadState.IDLE
+
def process_request(self, request, client):
method = request.get_method()
URI = request.get_uri()