From ddd377511212d24b667b0f2024112c43fec632e0eccafd297c8f4bfc13cdc2ce Mon Sep 17 00:00:00 2001 From: PioApocalypse Date: Tue, 10 Feb 2026 15:03:47 +0100 Subject: [PATCH] http error handling in APIHandler method get_entry_from_elabid() --- src/APIHandler.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/APIHandler.py b/src/APIHandler.py index 9a749f7..3bcef72 100644 --- a/src/APIHandler.py +++ b/src/APIHandler.py @@ -24,8 +24,16 @@ class APIHandler: url = f"{self.elaburl}/{entryType}/{elabid}", verify=True ) - if response.status_code // 100 in [2,3]: + if response.status_code // 100 in [1,2,3]: entry_data = response.json() return entry_data + elif response.status_code // 100 == 4: + match response.status_code: + case 401|403: + raise ConnectionError(f"Invalid API key or authentication method.") + case 404: + raise ConnectionError(f"404: Not Found. This means there's no resource with this elabid (wrong elabid?) on your eLabFTW (wrong endpoint?).") + case _: + raise ConnectionError(f"HTTP request failed with status code: {response.status_code} (NOTE: 4xx means user's fault).") else: - raise ConnectionError(f"HTTP request failed with status code: {response.status_code}.") \ No newline at end of file + raise ConnectionError(f"There's a problem on the server. Status code: {response.status_code}.") \ No newline at end of file