Skip to content

Commit

Permalink
Replace error log with exception log for K8s API exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
josefhandl committed May 6, 2024
1 parent a4fc645 commit 0f2555d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions kubespawner/reflector.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,18 @@ async def _list_and_update(self, resource_version=None):

list_method = getattr(self.api, self.list_method_name)

initial_resources_raw = await list_method(**kwargs)
if not initial_resources_raw.ok:
self.log.error(
f'Error when calling Kubernetes API.'
try:
initial_resources_raw = await list_method(**kwargs)
if not initial_resources_raw.ok:
raise client.ApiException(
status=initial_resources_raw.status,
reason=initial_resources_raw.reason
)
except client.ApiException:
self.log.exception(f'An error occurred when calling Kubernetes API.'
f' Status: {initial_resources_raw.status} {initial_resources_raw.reason}.'
f' Message: {(await initial_resources_raw.json())["message"]}'
)
raise client.ApiException(
status=initial_resources_raw.status, reason=initial_resources_raw.reason
)
f' Message: {(await initial_resources_raw.json())["message"]}')
raise

# This is an atomic operation on the dictionary!
initial_resources = json.loads(await initial_resources_raw.read())
Expand Down

0 comments on commit 0f2555d

Please sign in to comment.