async getExecutionError()

in source/analysis-monitor/lib/index.js [612:659]


  async getExecutionError(arn) {
    const step = new AWS.StepFunctions({
      apiVersion: '2016-11-23',
    });

    let response;
    let failed;
    do {
      response = await step.getExecutionHistory({
        executionArn: arn,
        maxResults: 100,
        reverseOrder: true,
        nextToken: (response || {}).nextToken,
      }).promise().catch(e => undefined);

      failed = response.events.filter(x => ([
        'Failed',
        'Aborted',
        'TimeOut',
      ].findIndex(x0 => x.type.indexOf(x0) >= 0) >= 0));
    } while ((response || {}).nextToken && !failed);

    let message;
    while (failed.length) {
      const task = failed.shift();
      if ((task.lambdaFunctionFailedEventDetails || {}).cause) {
        return task.lambdaFunctionFailedEventDetails.cause;
      }

      if ((task.lambdaFunctionTimedOutEventDetails || {}).cause) {
        return task.lambdaFunctionTimedOutEventDetails.cause;
      }

      if ((task.executionFailedEventDetails || {}).cause) {
        return task.executionFailedEventDetails.cause;
      }

      if ((task.taskTimedOutEventDetails || {}).cause) {
        return task.taskTimedOutEventDetails.cause;
      }

      if ((task.executionAbortedEventDetails || {}).cause) {
        return task.executionAbortedEventDetails.cause;
      }
      message = `${arn} ${task.type}`;
    }
    return message;
  }