Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle bad events #978

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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