From f05b78e0144abb6617b30b1f507f959f56705f9c Mon Sep 17 00:00:00 2001 From: tmtabor Date: Tue, 5 Sep 2023 09:50:27 -0700 Subject: [PATCH] Better handling of HTTP errors upon job submission --- gp/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gp/core.py b/gp/core.py index d72ca0e..b5e5dc5 100644 --- a/gp/core.py +++ b/gp/core.py @@ -120,7 +120,14 @@ def run_job(self, job_spec, wait_until_done=True): request.add_header('Authorization', self.authorization_header()) request.add_header('Content-Type', 'application/json') request.add_header('User-Agent', 'GenePatternRest') - response = urllib.request.urlopen(request, json_string) + try: + response = urllib.request.urlopen(request, json_string) + except urllib.error.HTTPError as e: + if e.code == 403: + print("job POST failed, your account is either over the data limit or you have too many jobs running") + else: + print(f" job POST failed, status code = {e.code}, {e.reason}") + return None if response.getcode() != 201: print(" job POST failed, status code = %i" % response.getcode()) return None