Skip to content

Commit

Permalink
Merge pull request #978 from PrefectHQ/bad-events
Browse files Browse the repository at this point in the history
handle bad events
  • Loading branch information
zzstoatzz authored Oct 14, 2024
2 parents e261437 + 8dc0fab commit a7af592
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cookbook/slackbot/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from marvin.utilities.strings import count_tokens, slice_tokens
from prefect import flow, task
from prefect.blocks.notifications import SlackWebhook
from prefect.states import Completed
from prefect.variables import Variable
from tools import (
Expand Down Expand Up @@ -126,7 +127,16 @@ async def handle_message(payload: SlackPayload):

@app.post("/chat")
async def chat_endpoint(request: Request):
payload = SlackPayload(**await request.json())
try:
payload = SlackPayload(**await request.json())
except Exception as e:
logger.error(f"Error parsing Slack payload: {e}")
slack_webhook = await SlackWebhook.load("marvin-bot-pager")
await slack_webhook.notify( # type: ignore
body=f"Error parsing Slack payload: {e}",
subject="Slackbot Error",
)
raise HTTPException(400, "Invalid event type")
match payload.type:
case "event_callback":
options = dict(
Expand Down

0 comments on commit a7af592

Please sign in to comment.