NGRP / node-red-contrib-viseo

Node-RED nodes OpenSourced by VISEO Technologies
Apache License 2.0
227 stars 83 forks source link

airtable: Crashes with uncaught exception if payload is missing or invalid #153

Open ralrom opened 4 years ago

ralrom commented 4 years ago

Hello, I am using the Airtable node from this package, and noticed that if no payload is specified, this node causes Node-RED to crash with an uncaught exception.

7 Apr 13:01:23 - [red] Uncaught Exception:
util.js:122
7 Apr 13:01:23 - TypeError: Cannot read property 'length' of undefined
    at cleanRecords (<PATH_TO_NODERED_APP>\node_modules\node-red-contrib-viseo-airtable\node-airtable.js:198:15)
    at <PATH_TO_NODERED_APP>\node_modules\node-red-contrib-viseo-airtable\node-airtable.js:137:19
    at <PATH_TO_NODERED_APP>\node_modules\node-red-contrib-viseo-airtable\node_modules\airtable\lib\table.js:99:20
    at Request._callback (<PATH_TO_NODERED_APP>\node_modules\node-red-contrib-viseo-airtable\node_modules\airtable\lib\run_action.js:69:9)
    at Request.self.callback (<PATH_TO_NODERED_APP>\node_modules\request\request.js:185:22)
    at Request.emit (events.js:210:5)
    at Request.<anonymous> (<PATH_TO_NODERED_APP>\node_modules\request\request.js:1161:10)
    at Request.emit (events.js:210:5)
    at IncomingMessage.<anonymous> (<PATH_TO_NODERED_APP>\node_modules\request\request.js:1083:12)
    at Object.onceWrapper (events.js:299:28)
    at IncomingMessage.emit (events.js:215:7)
    at endReadableNT (_stream_readable.js:1184:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

This error is caused by a call to the function cleanRecords which does a check on records.length before checking if records itself is valid:

if (records.length) {

If records is missing, or does not have a length property, this function throws an exception and stops the Node-RED server.