diff --git a/app/server/server.py b/app/server/server.py index e837717a..a8001c5b 100644 --- a/app/server/server.py +++ b/app/server/server.py @@ -82,6 +82,13 @@ class Config: extra = Extra.forbid +class UpptimeStatusPayload(BaseModel): + text: str | None = None + + class Config: + extra = Extra.forbid + + class AccessRequest(BaseModel): """ AccessRequest represents a request for access to an AWS account. @@ -423,10 +430,18 @@ def handle_webhook(id: str, payload: WebhookPayload | str, request: Request): request.state.bot.client, f"Error parsing AWS event due to {e.__class__.__qualname__}: ```{payload}```", ) - raise HTTPException( - status_code=500, - detail=f"Failed to parse AWS event message due to {e.__class__.__qualname__}: {e}", - ) + try: + payload = UpptimeStatusPayload.parse_raw(payload) + except Exception as e: + logging.error(e) + log_ops_message( + request.state.bot.client, + f"Error parsing Upptime status payload due to {e.__class__.__qualname__}: ```{payload}```", + ) + raise HTTPException( + status_code=500, + detail=f"Failed to parse payload due to {e.__class__.__qualname__}: {e}", + ) if payload.Type == "SubscriptionConfirmation": requests.get(payload.SubscribeURL, timeout=60) logging.info(f"Subscribed webhook {id} to topic {payload.TopicArn}") @@ -451,6 +466,8 @@ def handle_webhook(id: str, payload: WebhookPayload | str, request: Request): logging.info("No blocks to post, returning") return payload = WebhookPayload(blocks=blocks) + else: + payload = WebhookPayload(**payload.dict()) payload.channel = webhook["channel"]["S"] payload = append_incident_buttons(payload, id) try: