{"size": 793, "ext": "js", "max_stars_repo_path": "lib/retry-message.js", "max_stars_repo_name": "BonnierNews/lu-broker", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/retry-message.js", "max_issues_repo_name": "BonnierNews/lu-broker", "max_issues_repo_issues_event_min_datetime": "2022-02-19T11:22:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T06:29:24.000Z", "max_forks_repo_path": "lib/retry-message.js", "max_forks_repo_name": "BonnierNews/lu-broker", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 24.0303030303, "max_line_length": 103, "alphanum_fraction": 0.6721311475}
"use strict";
const config = require("exp-config");

function retryMessage(error, message, context, notify) {
  const {retryCount, logger} = context;
  const verboseError = buildError(error);
  message.errors = message.errors || [];
  message.errors.push(verboseError);

  const logMsg = `Got error: "${error.toString()}" when processing message ${JSON.stringify(message)}`;
  if (retryCount > 7) {
    logger.error(logMsg);
  } else {
    logger.info(logMsg);
  }

  notify.nack(false);
  if (config.envName === "test" && !config.boolean("silenceTestErrors")) {
    // eslint-disable-next-line no-console
    console.error(error);
  }
}

function buildError(error) {
  return {
    status: error.code,
    source: error.source,
    title: error.message
  };
}

module.exports = retryMessage;
