From 892dfdd9e01dea6fe211f6cfa2ee350e7a77af6f Mon Sep 17 00:00:00 2001 From: Harshit Nagar Date: Mon, 23 Feb 2026 23:35:41 +0530 Subject: [PATCH 1/2] Improve HTTP error handling for 401/403 and replace KeyError for 404 This PR improves HTTP error handling in the client. Changes: - Added explicit handling for 401 (Unauthorized) and 403 (Forbidden) status codes. - Replaced the use of KeyError for 404 responses with a more appropriate API error. - Improved error messages for better clarity and debugging. This aligns error handling more closely with standard HTTP semantics and avoids using KeyError for non-dictionary-related issues. Fixes #1409 --- src/blueapi/client/rest.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/blueapi/client/rest.py b/src/blueapi/client/rest.py index 52150d36f..645108d8f 100644 --- a/src/blueapi/client/rest.py +++ b/src/blueapi/client/rest.py @@ -1,3 +1,4 @@ +import code from collections.abc import Callable, Mapping from typing import Any, Literal, TypeVar @@ -104,8 +105,12 @@ def _exception(response: requests.Response) -> Exception | None: code = response.status_code if code < 400: return None + elif code == 401: + return BlueskyRemoteControlError(code, "Unauthorized: Authentication required.") + elif code == 403: + return BlueskyRemoteControlError(code, "Forbidden: You do not have permission.") elif code == 404: - return KeyError(str(response.json())) + return BlueskyRemoteControlError(code, "Resource not found.") else: return BlueskyRemoteControlError(code, str(response)) From f291ee3ba4eb1762e963bb40d42626305e463137 Mon Sep 17 00:00:00 2001 From: Harshit Nagar Date: Mon, 23 Feb 2026 23:48:57 +0530 Subject: [PATCH 2/2] Remove unused import of 'code' module --- src/blueapi/client/rest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/blueapi/client/rest.py b/src/blueapi/client/rest.py index 645108d8f..952da5fad 100644 --- a/src/blueapi/client/rest.py +++ b/src/blueapi/client/rest.py @@ -1,4 +1,3 @@ -import code from collections.abc import Callable, Mapping from typing import Any, Literal, TypeVar