Add errors handling

This commit is contained in:
Colin Goutte 2021-10-06 16:22:45 +02:00
parent 844aa68c57
commit 6c159bea46
1 changed files with 20 additions and 0 deletions

View File

@ -57,6 +57,15 @@ class Notifier:
{"changes": changes, "status": [x for x in status]}
)
def error_sonde(idsonde, kind="perte_contact_api"):
notifications[idsonde].append(
{
"changes": ["perte contact api"],
"status": ["Le monitoring est inacessible"],
}
)
breakpoint()
Notifier = Notifier()
@ -129,6 +138,17 @@ def list_notification_as_text(request: Request, idsonde: str):
)
@app.post("/sonde/{idsonde}/error")
def post_sonde_error(
idsonde: str, body: dict = Body(...), db: Session = Depends(get_db)
):
if not (sonde := crud.get_sonde(db, idsonde)):
return
Notifier.error_sonde(idsonde)
return
@app.post("/sonde/{idsonde}/")
def post_sonde_data(
idsonde: str, body: dict = Body(...), db: Session = Depends(get_db)