Add exception handling for chargepoint reset

This commit is contained in:
Oliver Traber 2024-04-15 00:03:32 +02:00
parent 6f998a3c58
commit 161c6aa027
Signed by: Bluemedia
GPG key ID: C0674B105057136C

View file

@ -130,9 +130,12 @@ async def reset_chargepoint(
api_key: str = Security(get_api_key) api_key: str = Security(get_api_key)
): ):
if chargepoint_manager.is_connected(chargepoint_id) == False: if chargepoint_manager.is_connected(chargepoint_id) == False:
raise HTTPException(status_code=423, detail="Chargepoint not connected") raise HTTPException(status_code=503, detail="Chargepoint not connected.")
try:
response = await chargepoint_manager.call( response = await chargepoint_manager.call(
chargepoint_id, chargepoint_id,
payload=ResetPayload(type=reset_request.type, evse_id=reset_request.evse_id) payload=ResetPayload(type=reset_request.type, evse_id=reset_request.evse_id)
) )
return ChargePointResetResponse(status=response.status) return ChargePointResetResponse(status=response.status)
except TimeoutError:
raise HTTPException(status_code=503, detail="Chargepoint didn't respond in time.")