Skip to content

Commit 2db8a5e

Browse files
author
Peter Amstutz
committed
Propagate status codes for slightly more useful error reporting.
1 parent 1382004 commit 2db8a5e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

wes_service/arvados_wes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import arvados
22
import arvados.util
33
import arvados.collection
4+
import arvados.errors
45
import os
56
import connexion
67
import json
78
import subprocess
89
import tempfile
10+
import functools
911
from wes_service.util import visit, WESBackend
1012

1113

@@ -26,6 +28,20 @@ def get_api():
2628
}
2729

2830

31+
def catch_exceptions(orig_func):
32+
"""Catch uncaught exceptions and turn them into http errors"""
33+
34+
@functools.wraps(orig_func)
35+
def catch_exceptions_wrapper(self, *args, **kwargs):
36+
try:
37+
return orig_func(self, *args, **kwargs)
38+
except arvados.errors.ApiError as e:
39+
return {"msg": e._get_reason(), "status_code": e.resp.status}, int(e.resp.status)
40+
except subprocess.CalledProcessError as e:
41+
return {"msg": str(e), "status_code": 500}, 500
42+
43+
return catch_exceptions_wrapper
44+
2945
class ArvadosBackend(WESBackend):
3046
def GetServiceInfo(self):
3147
return {
@@ -39,6 +55,7 @@ def GetServiceInfo(self):
3955
"key_values": {}
4056
}
4157

58+
@catch_exceptions
4259
def ListWorkflows(self):
4360
api = get_api()
4461

@@ -60,6 +77,7 @@ def ListWorkflows(self):
6077
"next_page_token": ""
6178
}
6279

80+
@catch_exceptions
6381
def RunWorkflow(self, body):
6482
if body["workflow_type"] != "CWL" or body["workflow_type_version"] != "v1.0": # NOQA
6583
return
@@ -77,6 +95,7 @@ def RunWorkflow(self, body):
7795
body.get("workflow_url"), inputtemp.name], env=env).strip() # NOQA
7896
return {"workflow_id": workflow_id}
7997

98+
@catch_exceptions
8099
def GetWorkflowLog(self, workflow_id):
81100
api = get_api()
82101

@@ -120,11 +139,13 @@ def keepref(d):
120139
r["workflow_log"]["exit_code"] = container["exit_code"]
121140
return r
122141

142+
@catch_exceptions
123143
def CancelJob(self, workflow_id): # NOQA
124144
api = get_api()
125145
request = api.container_requests().update(body={"priority": 0}).execute() # NOQA
126146
return {"workflow_id": request["uuid"]}
127147

148+
@catch_exceptions
128149
def GetWorkflowStatus(self, workflow_id):
129150
api = get_api()
130151
request = api.container_requests().get(uuid=workflow_id).execute()

0 commit comments

Comments
 (0)