Skip to content

Commit

Permalink
improve error reporting to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshawkes committed Nov 16, 2024
1 parent c0714dd commit b5c4bef
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions polytope_server/common/datasource/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def dispatch(self, request, input_data) -> bool:
if hasattr(self, "silent_match") and self.silent_match:
pass
else:
request.user_message += "Skipping datasource {} due to match error: {}\n".format(
self.get_type(), repr(e)
request.user_message += "Skipping datasource: {}\n".format(
repr(e)
)
tb = traceback.format_exception(None, e, e.__traceback__)
logging.info(tb)
Expand All @@ -97,7 +97,7 @@ def dispatch(self, request, input_data) -> bool:
datasource_role_rules = self.config.get("roles", None)
if datasource_role_rules is not None:
if not any(role in request.user.roles for role in datasource_role_rules.get(request.user.realm, [])):
request.user_message += "Skipping datasource {}. User is forbidden.\n".format(self.get_type())
request.user_message += "Skipping datasource {}. User is not authorised.\n".format(self.get_type())
return False

# Retrieve/Archive/etc.
Expand All @@ -111,7 +111,7 @@ def dispatch(self, request, input_data) -> bool:
raise NotImplementedError()

except NotImplementedError as e:
request.user_message += "Skipping datasource {}. Verb {} not available: {}\n".format(
request.user_message += "Skipping datasource {}. Method '{}' not available: {}\n".format(
self.get_type(), request.verb, repr(e)
)
return False
Expand Down
6 changes: 3 additions & 3 deletions polytope_server/common/datasource/polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ def match(self, request):

# Check that there is a feature specified in the request
if "feature" not in r:
raise Exception("Request does not contain expected key 'feature'")
raise Exception("Request does not contain key 'feature'")

for k, v in self.match_rules.items():
# Check that all required keys exist
if k not in r:
raise Exception("Request does not contain expected key {}".format(k))
raise Exception("Request does not contain key {}".format(k))

# ... and check the value of other keys
v = [v] if isinstance(v, str) else v

if r[k] not in v:
raise Exception("got {} : {}, but expected one of {}".format(k, r[k], v))
raise Exception("got {}: {}, not one of {}".format(k, r[k], v))

# Check that there is only one value if required
for k, v in r.items():
Expand Down
3 changes: 2 additions & 1 deletion polytope_server/common/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def check_released(
if datetime.now() < release_date:
raise PolytopeError(
f"Data not yet released for date: {date_in}, class: {c}, stream: {s}, "
f"domain: {dom}, time: {time_in}, step: {step}, type {diss}"
f"domain: {dom}, time: {time_in}, step: {step}, type {diss}. "
f"Release time is {release_date}."
)

def get_release_time_and_delta_day(
Expand Down
4 changes: 2 additions & 2 deletions polytope_server/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ def process_request(self, request):
datasource.destroy(request)

if datasource is None:
request.user_message += "Failed to process request."
# request.user_message += "Failed to process request."
logging.info(request.user_message, extra={"request_id": id})
raise Exception("Failed to process request.")
raise Exception("Request was not accepted by any datasources.")
else:
request.user_message += "Success"

Expand Down

0 comments on commit b5c4bef

Please sign in to comment.