Articles in this section

JavaScript example: Detect an empty FTP directory

This article explains how to generate an error if an FTP request attempts to read a file from an empty location. The following code sample contains a JavaScript function that can be used to check for empty data returned from an import step within a flow:

function checkFTPSource (options) {
  var errorMessage = '';
 
  if(options.data === null) {
    errorMessage = 'data is NULL';
  }else if (options.data.length === 0) {
    errorMessage = 'No files in source FTP location!';
  }
 
  var errorsArray = options.errors;
  if (errorMessage.length > 0) {
    const error = {code:1, message: errorMessage, source:'checkFTPSource'};
    errorsArray.push(error);
  }
 
  return {
    data: options.data,
    errors: errorsArray
  }
}

Configure this script in an export hook:

360064567131-Screenshot_2020-08-11_at_16.22.12.png

For more information on hooks, see Hooks for integrator.io.

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

Comments

0 comments

Please sign in to leave a comment.