mirror of
https://github.com/fusion44/blitz_api.git
synced 2026-08-13 11:52:45 +02:00
refactor(api): handle warmup fetch errors explicitly in _handle (#245)
The warmup consumer already avoids the old .dict()-on-HTTPException crash,
but HTTPException/Err results fell through the 'unknown data type' arm,
double-logging and mislabelling known errors. Give them explicit match
arms: HTTPException logs at info (the real error is already logged in
_convert_warmup_exceptions) and Err forwards report.format() instead of
its repr. Error event payload is unchanged ({"error": <string>}).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
6e3238a5a7
commit
d694f8498a
1 changed files with 15 additions and 5 deletions
20
app/main.py
20
app/main.py
|
|
@ -46,7 +46,7 @@ from app.external.fastapi_plugins_redis import (
|
||||||
redis_plugin,
|
redis_plugin,
|
||||||
registered_configuration,
|
registered_configuration,
|
||||||
)
|
)
|
||||||
from app.external.result_type.src.result.result import Ok
|
from app.external.result_type.src.result.result import Err, Ok
|
||||||
from app.lightning.models import LnInitState
|
from app.lightning.models import LnInitState
|
||||||
from app.lightning.router import router as ln_router
|
from app.lightning.router import router as ln_router
|
||||||
from app.lightning.service import initialize_ln_repo, register_lightning_listener
|
from app.lightning.service import initialize_ln_repo, register_lightning_listener
|
||||||
|
|
@ -348,14 +348,24 @@ async def warmup_new_connections():
|
||||||
case Ok(data) if not data:
|
case Ok(data) if not data:
|
||||||
logger.debug(f"No data to send for warmup event {event}")
|
logger.debug(f"No data to send for warmup event {event}")
|
||||||
return
|
return
|
||||||
case data:
|
case HTTPException():
|
||||||
|
# A data source failed while gathering warmup data. The
|
||||||
|
# underlying error is already logged in _convert_warmup_exceptions;
|
||||||
|
# forward a clear error so the client isn't left waiting for this
|
||||||
|
# event.
|
||||||
|
logger.info(f"Error while fetching warmup data for {event}: {res}")
|
||||||
|
return await _send_ws_event(id, event, {"error": f"{res}"})
|
||||||
|
case Err(report):
|
||||||
|
logger.error(
|
||||||
|
f"Error while fetching warmup data for {event}: {report.format()}"
|
||||||
|
)
|
||||||
|
return await _send_ws_event(id, event, {"error": report.format()})
|
||||||
|
case _:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Got unknown data type while handling warmup "
|
f"Got unknown data type while handling warmup "
|
||||||
f"data {event}: {type(res)}"
|
f"data {event}: {type(res)}"
|
||||||
)
|
)
|
||||||
|
return await _send_ws_event(id, event, {"error": f"{res}"})
|
||||||
logger.error(f"Error while fetching warmup_data for {event}: {res}")
|
|
||||||
return await _send_ws_event(id, event, {"error": f"{res}"})
|
|
||||||
|
|
||||||
global new_connections
|
global new_connections
|
||||||
if len(new_connections) == 0:
|
if len(new_connections) == 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue