warehouse.ai-api-client
Advanced tools
Comparing version 2.0.1 to 2.1.0
28
index.js
@@ -1,3 +0,1 @@ | ||
const debug = require('diagnostics')('warehouse'); | ||
@@ -8,2 +6,3 @@ const qs = require('querystringify'); | ||
const Builds = require('./builds'); | ||
const retry = require('retryme'); | ||
@@ -34,2 +33,3 @@ /** | ||
options = options || {}; | ||
this.retry = options.retry || {}; | ||
this.uri = options.uri; | ||
@@ -110,12 +110,24 @@ this.auth = options.auth ? 'Bearer ' + options.auth : null; | ||
request(options, function replied(error, response, body) { | ||
if (error) return next(error); | ||
// | ||
// Ignore 404 and 400's when it comes to retries | ||
// | ||
const operation = retry.op(this.retry, (err) => { | ||
return err.message.includes('404') | ||
|| err.message.includes('400'); | ||
}); | ||
if (response.statusCode === 404) return next(new Error(`404 Not Found ${JSON.stringify(body)}`)); | ||
operation.attempt(fn => { | ||
request(options, function replied(error, response, body) { | ||
if (error) return fn(error); | ||
if (response.statusCode < 200 || response.statusCode > 299) return next(new Error(`Invalid status code ${response.statusCode} ${body ? JSON.stringify(body) : ''}`)); | ||
if (response.statusCode === 404) return fn(new Error(`404 Not Found ${JSON.stringify(body)}`)); | ||
if (response.statusCode === 400) return fn(new Error(`400 Bad Request ${JSON.stringify(body)}`)); | ||
next(null, body); | ||
}); | ||
if (response.statusCode < 200 || response.statusCode > 299) return fn(new Error(`Invalid status code ${response.statusCode} ${body ? JSON.stringify(body) : ''}`)); | ||
fn(null, body); | ||
}); | ||
}, next); | ||
return this; | ||
@@ -122,0 +134,0 @@ }; |
{ | ||
"name": "warehouse.ai-api-client", | ||
"description": "Node.JS API to communicate with warehouse.ai", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"main": "index.js", | ||
@@ -29,3 +29,4 @@ "scripts": { | ||
"querystringify": "0.0.3", | ||
"request": "^2.70.0" | ||
"request": "^2.70.0", | ||
"retryme": "^1.0.0" | ||
}, | ||
@@ -32,0 +33,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11084
268
5
+ Addedretryme@^1.0.0
+ Addedbacko@1.1.0(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addedcolornames@1.1.1(transitive)
+ Addedcolorspace@1.1.4(transitive)
+ Addeddiagnostics@1.1.1(transitive)
+ Addedfailure@1.1.1(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addedkuler@1.0.1(transitive)
+ Addedone-time@0.0.4(transitive)
+ Addedretryme@1.1.0(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedtext-hex@1.0.0(transitive)