GV14982 / async-airtable

A lightweight npm package to handle working with the Airtable API.
https://www.npmjs.com/package/asyncairtable
MIT License
54 stars 5 forks source link

Uncaught Iteration Timeout errors from Airtable #58

Open MoralCode opened 3 years ago

MoralCode commented 3 years ago

I've been seeing quite a few instances of the following error in the monitoring software we use for vacfind:

Message: Error: Error: {"error":{"type":"LIST_RECORDS_ITERATOR_NOT_AVAILABLE"}}
at this.select/< line 1, column 6350 (https://vacfind.org/assets/js/asyncAirtable-beta.min.js:1)
at s line 1, column 4770 (https://vacfind.org/assets/js/asyncAirtable-beta.min.js:1)

I'm working on getting the included sourcemaps to process correctly, but this seems to me to be a relatively straightforward case of an UnhandledPromiseRejection.

Searching online leads me to this issue that mentions this error message and refers to the Airtable API docs which state that:

Iteration may timeout due to client inactivity or server restarts. In that case, the client will receive a 422 response with error message LIST_RECORDS_ITERATOR_NOT_AVAILABLE. It may then restart iteration from the beginning.

I have not personally found a way to reproduce this issue since the docs seem to say that it only happens in cases of timeouts or the airtable server going down. Although airtable seems to briefly (<30 sec) go down somewhat frequently, this isn't something that I am able to reproduce intentionally.

Would you accept a PR to add in a handler to catch these 422 LIST_RECORDS_ITERATOR_NOT_AVAILABLE errors, and If so, how would you prefer to have AsyncAirtable handle it?

MoralCode commented 3 years ago

From looking at the minified code around the place where it says the error is, it seems like this issue is being caused by this Async call: https://github.com/GV14982/async-airtable/blob/d9b517f67349f0dceb41f56846e52dc06ea7e1cb/src/asyncAirtable.ts#L264-L276

Edit: the sourcemap seems to suggest its actually this catch block that's throwing the error : https://github.com/GV14982/async-airtable/blob/d9b517f67349f0dceb41f56846e52dc06ea7e1cb/src/asyncAirtable.ts#L184-L186

i suspect this happens in cases where there are multiple pages of records to fetch and the Airtable server goes down or something in the middle of that interaction

GV14982 commented 3 years ago

Thanks for all your work on this!

Yeah feel free to submit a PR. If you opt not to I will take a look at it as soon as I have some more time!