How to use the @bugsnag/core/lib/es-utils.reduce function in @bugsnag/core

To help you get started, we’ve selected a few @bugsnag/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bugsnag / bugsnag-js / packages / plugin-inline-script-content / inline-script-content.js View on Github external
const addSurroundingCode = lineNumber => {
      // get whatever html has rendered at this point
      if (!DOMContentLoaded || !html) html = getHtml()
      // simulate the raw html
      const htmlLines = [ '' ].concat(html.split('\n'))
      const zeroBasedLine = lineNumber - 1
      const start = Math.max(zeroBasedLine - 3, 0)
      const end = Math.min(zeroBasedLine + 3, htmlLines.length)
      return reduce(htmlLines.slice(start, end), (accum, line, i) => {
        accum[start + 1 + i] = line.length <= MAX_LINE_LENGTH ? line : line.substr(0, MAX_LINE_LENGTH)
        return accum
      }, {})
    }
github bugsnag / bugsnag-js / packages / plugin-console-breadcrumbs / console-breadcrumbs.js View on Github external
console[method] = (...args) => {
      client.leaveBreadcrumb('Console output', reduce(args, (accum, arg, i) => {
        // do the best/simplest stringification of each argument
        let stringified = '[Unknown value]'
        // this may fail if the input is:
        // - an object whose [[Prototype]] is null (no toString)
        // - an object with a broken toString or @@toPrimitive implementation
        try { stringified = String(arg) } catch (e) {}
        // if it stringifies to [object Object] attempt to JSON stringify
        if (stringified === '[object Object]') {
          // catch stringify errors and fallback to [object Object]
          try { stringified = JSON.stringify(arg) } catch (e) {}
        }
        accum[`[${i}]`] = stringified
        return accum
      }, {
        severity: method.indexOf('group') === 0 ? 'log' : method
      }), 'log')
github bugsnag / bugsnag-js / packages / plugin-window-unhandled-rejection / unhandled-rejection.js View on Github external
isBluebird = true
      }
    } catch (e) {}

    const handledState = {
      severity: 'error',
      unhandled: true,
      severityReason: { type: 'unhandledPromiseRejection' }
    }

    let report
    if (error && hasStack(error)) {
      // if it quacks like an Error…
      report = new client.BugsnagReport(error.name, error.message, ErrorStackParser.parse(error), handledState, error)
      if (isBluebird) {
        report.stacktrace = reduce(report.stacktrace, fixBluebirdStacktrace(error), [])
      }
    } else {
      // if it doesn't…
      const msg = 'Rejection reason was not an Error. See "Promise" tab for more detail.'
      report = new client.BugsnagReport(
        error && error.name ? error.name : 'UnhandledRejection',
        error && error.message ? error.message : msg,
        [],
        handledState,
        error
      )
      // stuff the rejection reason into metaData, it could be useful
      report.updateMetaData('promise', 'rejection reason', serializableReason(error))
    }

    client.notify(report)