11from typing import Any
22
3+ from benchling_sdk .apps .status .errors import AppUserFacingError
34from benchling_sdk .models .webhooks .v0 import (
45 CanvasInitializeWebhookV0 ,
56 CanvasInteractionWebhookV0 ,
@@ -25,11 +26,17 @@ def handle_webhook(webhook_dict: dict[str, Any]) -> None:
2526 # Could also choose to route on webhook.message.type
2627 # Note: if your manifest specifies more than one item in `features`,
2728 # then `webhook.message.feature_id` may also need to be part of your routing logic
28- if isinstance (webhook .message , CanvasInitializeWebhookV0 ):
29- render_search_canvas (app , webhook .message )
30- elif isinstance (webhook .message , CanvasInteractionWebhookV0 ):
31- route_interaction_webhook (app , webhook .message )
32- else :
33- # Should only happen if the app's manifest requests webhooks that aren't handled in its code paths
34- raise UnsupportedWebhookError (f"Received an unsupported webhook type: { webhook } " )
35- logger .debug ("Successfully completed request for webhook: %s" , webhook_dict )
29+ try :
30+ if isinstance (webhook .message , CanvasInitializeWebhookV0 ):
31+ render_search_canvas (app , webhook .message )
32+ elif isinstance (webhook .message , CanvasInteractionWebhookV0 ):
33+ route_interaction_webhook (app , webhook .message )
34+ else :
35+ # Should only happen if the app's manifest requests webhooks that aren't handled in its code paths
36+ raise UnsupportedWebhookError (f"Received an unsupported webhook type: { webhook } " )
37+ logger .debug ("Successfully completed request for webhook: %s" , webhook_dict )
38+ # We want errors shown to the user to end control flow, but we don't want them to propagate
39+ # and show as errors in our logs.
40+ # For this example, Flask error handler won't intercept this since we're within a thread
41+ except AppUserFacingError as e :
42+ logger .debug ("Exiting with client error: %s" , e )
0 commit comments