Error handling in Zapier Functions

You can handle errors from apps and from Python in Zapier Functions by using try except blocks and two classes: Exception and ZapierActionError.

Beta

This product is in open beta. It’s available for use but still in active development and may change.

Error classes

There are two classes you can use to handle errors in Zapier Functions:

  • Exception: a broad class that catches all errors, including Python errors.
  • ZapierActionError: this class catches only errors for Zapier actions included in your code.

You can use them while writing your code to take different actions depending on the type of error.

Implement error handling

To handle errors in Zap actions:

  1. From the Functions home, select the function.
  2. Click the Explorer icon on the left to see all function files. 
  3. Open the main.py file.
  4. Enclose the action code within the try block.
  5. Write an exception block right after, providing alternative instructions for errors. You can add multiple except blocks, and also use else and finally blocks.
try:
 zapier.action.slack.direct_message(
   account_id=50715278,
   params={     
     "channel":"ABCDEFG",  # To Username
     "text":"this is a direct message",  # Message Text
   },
   type_of="write",
 )
except ZapierActionError as e:
 zapier.action.slack.direct_message(
   account_id=50715278,
   params={     
     "channel":"HIJKLMN",  # To Username
     "text":"Your action had an error!",  # Message Text
   },
   type_of="write",
 )
Tip

Check the logs for error messages and use the messages in if conditions to take different actions depending on the error.

Provide feedback and get help

Submit a feature request, provide feedback on existing features, or get help from the Zapier Functions team. You can also discuss Functions with other users on Zapier's Early Access Program Slack.

Was this article helpful?
0 out of 1 found this helpful