Socket
Socket
Sign inDemoInstall

bugsnag-build-reporter

Package Overview
Dependencies
88
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

.npmignore

19

lib/send.js

@@ -0,1 +1,3 @@

'use strict'
const https = require('https')

@@ -5,4 +7,17 @@ const http = require('http')

const url = require('url')
const MAX_ATTEMPTS = 5
const RETRY_INTERVAL = process.env.BUGSNAG_RETRY_INTERVAL || 1000
module.exports = (endpoint, data, onSuccess, onError) => {
let attempts = 0
const maybeRetry = (err) => {
attempts++
if (err && err.isRetryable && attempts < MAX_ATTEMPTS) return setTimeout(go, RETRY_INTERVAL)
return onError(err)
}
const go = () => send(endpoint, data, onSuccess, maybeRetry)
go()
}
const send = (endpoint, data, onSuccess, onError) => {
const parsedUrl = url.parse(endpoint)

@@ -23,3 +38,5 @@ const payload = JSON.stringify(data)

if (res.statusCode !== 400) {
return onError(new Error(`HTTP status ${res.statusCode} received from builds API`))
const err = new Error(`HTTP status ${res.statusCode} received from builds API`)
err.isRetryable = true
return onError(err)
}

@@ -26,0 +43,0 @@ try {

'use strict'
process.env.BUGSNAG_RETRY_INTERVAL = 50
const test = require('tape')

@@ -51,2 +53,25 @@ const http = require('http')

test('send(): retry (500)', t => {
t.plan(1)
let n = 0
const server = http.createServer((req, res) => {
n++
if (n < 4) {
res.statusCode = 500
return res.end('error')
} else {
return res.end('ok')
}
})
server.listen()
send(`http://localhost:${server.address().port}`, {}, () => {
server.close()
t.equal(n, 4, 'it should make multiple attempts')
t.end()
}, (err) => {
server.close()
t.end(err)
})
})
test('send(): unsuccessful (400)', t => {

@@ -72,2 +97,25 @@ t.plan(3)

test('send(): unsuccessful, doesn’t retry (400)', t => {
t.plan(4)
let n = 0
const server = http.createServer((req, res) => {
n++
res.statusCode = 400
res.setHeader('content-type', 'application/json')
res.end('{ "errors": [ "flipflop is not a valid crankworble" ] }')
})
server.listen()
send(`http://localhost:${server.address().port}`, {}, () => {
server.close()
t.fail('send should not succeed')
}, (err) => {
server.close()
t.ok(err)
t.equal(n, 1, 'It should never retry a bad request')
t.equal(err.message, 'Invalid payload sent to builds API')
t.deepEqual(err.errors, [ 'flipflop is not a valid crankworble' ])
t.end()
})
})
test('send(): unsuccessful (400, bad json)', t => {

@@ -74,0 +122,0 @@ t.plan(2)

2

package.json
{
"name": "bugsnag-build-reporter",
"version": "1.0.0",
"version": "1.0.1",
"description": "A tool for reporting your application’s builds to Bugsnag",

@@ -5,0 +5,0 @@ "keywords": [

# bugsnag-build-reporter
[![Build status](https://travis-ci.org/bugsnag/bugsnag-build-reporter.svg?branch=master)](https://travis-ci.org/bugsnag/bugsnag-build-reporter)
[![Build status](https://travis-ci.org/bugsnag/bugsnag-build-reporter-node.svg?branch=master)](https://travis-ci.org/bugsnag/bugsnag-build-reporter-node)
[![NPM](https://img.shields.io/npm/v/bugsnag-build-reporter.svg)](https://npmjs.org/package/bugsnag-build-reporter)

@@ -4,0 +4,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc