Skip to content

Commit

Permalink
Add context to TimeoutErrors (#201)
Browse files Browse the repository at this point in the history
`ChargePoint.call()` raises a `asyncio.TimeoutError` if a call isn't
answered withing a given time.

However, the `asyncio.TimeoutError` is missing context. The lack of
context makes interpreting this exception hard than it should be.

This commit add that context.

Fixes: #200
  • Loading branch information
OrangeTux authored Apr 21, 2021
1 parent 6cef24b commit 133ffa9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,15 @@ async def call(self, payload, suppress=True):
# a time.
async with self._call_lock:
await self._send(call.to_json())
response = \
await self._get_specific_response(call.unique_id,
self._response_timeout)
try:
response = \
await self._get_specific_response(call.unique_id,
self._response_timeout)
except asyncio.TimeoutError:
raise asyncio.TimeoutError(
f"Waited {self._response_timeout}s for response on "
f"{call.to_json()}."
)

if response.message_type_id == MessageType.CallError:
LOGGER.warning("Received a CALLError: %s'", response)
Expand Down

0 comments on commit 133ffa9

Please sign in to comment.