Debug Zapier custom code

Throw exceptions to get debug information

Ronny Roeller
NEXT Engineering
2 min readJul 5, 2023

--

Zapier connects your app to a wide ecosystem of other apps. Best of all, it enables users to add business logic in these workflows.

One of the cool Zapier features is that it allows to write JavaScript code once one outgrows the form mode. For example, instead of just a simple OAuth configuration, the user could enter its tenant, and Zapier switches between different tenant-specific OAuth providers.

But the more business logic, the more bugs.

And that’s where things can get challenging: Zapier doesn’t expose any debug information about which data gets sent to the OAuth endpoint. There is also no possibility to write own log messages.

The best option we found is to throw from the JavaScript script an exception with all debug information. For example, to get the request options, replace the request code by throwing an error:

throw new Error(JSON.stringify(options));
/*
return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;
// You can do any parsing you need for results here before returning them
return results;
});
*/

Zapier prints the debug information then as part of its error messages:

Happy coding!

Photo: Thomas Altfather Good

--

--

Ronny Roeller
NEXT Engineering

CTO at nextapp.co # Product discovery platform for high performing teams that bring their customers into every decision