Skip to content

Commit

Permalink
Merge pull request #333 from Snuffy2/Show-HTTP-Status-Errors-4xx-in-C…
Browse files Browse the repository at this point in the history
…onfig-Flow

Throw ClientResponseError for HTTP Status Errors 4xx
  • Loading branch information
alexdelprete authored Dec 4, 2024
2 parents 348120b + 640f832 commit adbc2f4
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions custom_components/opnsense/pyopnsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,23 @@ async def _get_from_stream(self, path: str) -> Mapping[str, Any] | list:

# _LOGGER.debug(f"[get_from_stream] response_json ({type(response_json).__name__}): {response_json}")
return response_json # Exit after processing the second message

elif response.status == 403:
_LOGGER.error(
f"Permission Error in {inspect.currentframe().f_back.f_code.co_qualname.strip('_')}. Path: {url}. Ensure the OPNsense user connected to HA has full Admin access."
)
else:
_LOGGER.error(
f"Error in {inspect.currentframe().f_back.f_code.co_qualname.strip('_')}. Path: {url}. Response {response.status}: {response.reason}"
)
if response.status == 403:
_LOGGER.error(
f"Permission Error in {inspect.currentframe().f_back.f_code.co_qualname.strip('_')}. Path: {url}. Ensure the OPNsense user connected to HA has full Admin access."
)
else:
_LOGGER.error(
f"Error in {inspect.currentframe().f_back.f_code.co_qualname.strip('_')}. Path: {url}. Response {response.status}: {response.reason}"
)
if self._initial:
raise aiohttp.ClientResponseError(
request_info=response.request_info,
history=response.history,
status=response.status,
message=f"HTTP Status Error: {response.status} {response.reason}",
headers=response.headers,
)
except aiohttp.ClientError as e:
_LOGGER.error(f"Client error. {e.__class__.__qualname__}: {e}")
if self._initial:
Expand Down Expand Up @@ -369,6 +377,14 @@ async def _get(self, path: str) -> Mapping[str, Any] | list:
_LOGGER.error(
f"Error in {inspect.currentframe().f_back.f_code.co_qualname.strip('_')}. Path: {url}. Response {response.status}: {response.reason}"
)
if self._initial:
raise aiohttp.ClientResponseError(
request_info=response.request_info,
history=response.history,
status=response.status,
message=f"HTTP Status Error: {response.status} {response.reason}",
headers=response.headers,
)
except aiohttp.ClientError as e:
_LOGGER.error(f"Client error. {e.__class__.__qualname__}: {e}")
if self._initial:
Expand Down Expand Up @@ -396,14 +412,22 @@ async def _post(self, path: str, payload=None) -> Mapping[str, Any] | list:
content_type=None
)
return response_json
elif response.status == 403:
if response.status == 403:
_LOGGER.error(
f"Permission Error in {inspect.currentframe().f_back.f_code.co_qualname.strip('_')}. Path: {url}. Ensure the OPNsense user connected to HA has full Admin access"
)
else:
_LOGGER.error(
f"Error in {inspect.currentframe().f_back.f_code.co_qualname.strip('_')}. Path: {url}. Response {response.status}: {response.reason}"
)
if self._initial:
raise aiohttp.ClientResponseError(
request_info=response.request_info,
history=response.history,
status=response.status,
message=f"HTTP Status Error: {response.status} {response.reason}",
headers=response.headers,
)
except aiohttp.ClientError as e:
_LOGGER.error(f"Client error. {e.__class__.__qualname__}: {e}")
if self._initial:
Expand Down

0 comments on commit adbc2f4

Please sign in to comment.