From ad7d8ac72470e37c909c66613ab98ce72387648c Mon Sep 17 00:00:00 2001 From: Julien Perrochet Date: Fri, 8 Mar 2024 13:29:35 +0100 Subject: [PATCH] [uss_qualifier] add utility properties to QueryError --- monitoring/monitorlib/fetch/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/monitoring/monitorlib/fetch/__init__.py b/monitoring/monitorlib/fetch/__init__.py index 74a0f44841..ee6e4610bb 100644 --- a/monitoring/monitorlib/fetch/__init__.py +++ b/monitoring/monitorlib/fetch/__init__.py @@ -459,6 +459,26 @@ def __init__(self, msg: str, queries: Optional[Union[Query, List[Query]]] = None else: self.queries = queries + @property + def last_status_code(self) -> int: + """Returns the status code of the last query present in this QueryError, + or 999 if this error contains no queries.""" + if len(self.queries) == 0: + return 999 + return self.queries[-1].status_code + + @property + def query_timestamps(self) -> List[datetime.datetime]: + """Returns the timestamps of all queries present in this QueryError.""" + return [q.request.timestamp for q in self.queries] + + @property + def last_query(self) -> Optional[Query]: + """Returns the last query present in this QueryError, or None if this error contains no queries.""" + if len(self.queries) == 0: + return None + return self.queries[-1] + @property def stacktrace(self) -> str: return stacktrace_string(self)