Skip to content
Advertisement

How to avoid empty object error in a loop using Google Apps Script?

I’m calling an API and getting data going through its pagination. When I get to the last page, though, the obejct giving me the last page is empty and it’s throwing the following error: TypeError: Cannot convert undefined or null to object Besides, I don’t any data from that last page.

Here’s the pagination information I get:

JavaScript

Here’s the code I’m using to get the data:

JavaScript

Advertisement

Answer

You might use an if statement and continue. I.E. replace

JavaScript

by

JavaScript

Another option is to use try...catch

Resources

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement