<commit_before>const payload = require('@bugsnag/core/lib/json-payload')
const { isoDate } = require('@bugsnag/core/lib/es-utils')
const UndeliveredPayloadQueue = require('./queue')
const NetworkStatus = require('./network-status')
const RedeliveryLoop = require('./redelivery')

module.exports = (client, fetch = global.fetch) => {
  const networkStatus = new NetworkStatus()

  const send = (url, opts, cb) => {
    fetch(url, opts)
      .then(response => {
        if (response.ok) return response.text()
        const err = new Error(`Bad status code from API: ${response.status}`)
        err.isRetryable = isRetryable(response.status)
        return Promise.reject(err)
      })
      .then(() => cb(null))
      .catch(err => cb(err))
  }

  const logError = e => client._logger.error('Error redelivering payload', e)

  const enqueue = async (payloadKind, failedPayload) => {
    client._logger.info(`Writing ${payloadKind} payloads to cache`)
    await queues[payloadKind].enqueue(failedPayload, logError)
    if (networkStatus.isConnected) queueConsumers[payloadKind].start()
  }

  const onerror = async (err, failedPayload, payloadKind, cb) => {
    client._logger.error(`${payloadKind} failed to send…\n${(err && err.stack) ? err.stack : err}`, err)
    if (failedPayload && err.isRetryable !== false) enqueue(payloadKind, failedPayload)
    cb(err)
  }

  const { queues, queueConsumers } = initRedelivery(networkStatus, logError, send)

  return {
    sendReport: (report, cb = () => {}) => {
      const url = client.config.endpoints.notify

      let body, opts
      try {
        body = payload.report(report, client.config.filters)
        opts = {<commit_msg>fix(expo-delivery): Remove extraneous "s" from log message<commit_after>const payload = require('@bugsnag/core/lib/json-payload')
const { isoDate } = require('@bugsnag/core/lib/es-utils')
const UndeliveredPayloadQueue = require('./queue')
const NetworkStatus = require('./network-status')
const RedeliveryLoop = require('./redelivery')

module.exports = (client, fetch = global.fetch) => {
  const networkStatus = new NetworkStatus()

  const send = (url, opts, cb) => {
    fetch(url, opts)
      .then(response => {
        if (response.ok) return response.text()
        const err = new Error(`Bad status code from API: ${response.status}`)
        err.isRetryable = isRetryable(response.status)
        return Promise.reject(err)
      })
      .then(() => cb(null))
      .catch(err => cb(err))
  }

  const logError = e => client._logger.error('Error redelivering payload', e)

  const enqueue = async (payloadKind, failedPayload) => {
    client._logger.info(`Writing ${payloadKind} payload to cache`)
    await queues[payloadKind].enqueue(failedPayload, logError)
    if (networkStatus.isConnected) queueConsumers[payloadKind].start()
  }

  const onerror = async (err, failedPayload, payloadKind, cb) => {
    client._logger.error(`${payloadKind} failed to send…\n${(err && err.stack) ? err.stack : err}`, err)
    if (failedPayload && err.isRetryable !== false) enqueue(payloadKind, failedPayload)
    cb(err)
  }

  const { queues, queueConsumers } = initRedelivery(networkStatus, logError, send)

  return {
    sendReport: (report, cb = () => {}) => {
      const url = client.config.endpoints.notify

      let body, opts
      try {
        body = payload.report(report, client.config.filters)
        opts = {
{'fraction_non_alphanumeric': 0.1450381679389313, 'fraction_numerical': 0.0, 'mean_word_length': 3.616531165311653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '909904', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1025, 'n_words': 242}