Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cuddle

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cuddle - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

v1.3.0
----
* Auto-retry for error 500s
* Use the last error when max retry is reached
v1.2.0

@@ -2,0 +9,0 @@ ----

48

index.js

@@ -149,2 +149,3 @@ 'use strict';

this.errors = [];
this.last_error = null;

@@ -287,13 +288,20 @@ this.end = this.then;

if (this.retries++ < this._max_retry) {
this.log('warn', 'Retrying request');
if (this.last_error) {
this.errors.push(this.last_error);
}
if (++this.retries < this._max_retry) {
this.log('warn', 'Retrying request', this.retries, this.errors);
return this.then(this._final_cb);
}
const last_error = this.errors.pop();
last_error.max_retry_reached = true;
last_error.errors = this.errors;
this.cb(
{
message: 'Reached max retries',
errors: this.errors,
url: this.uri
},
last_error,
null,

@@ -404,3 +412,3 @@ this,

this.log('error', 'Response closed');
this.errors.push('Response closed');
this.last_error = 'Response closed';
this.retry();

@@ -411,3 +419,3 @@ });

this.log('error', 'Response error', err);
this.errors.push('Response closed');
this.last_error = err;
this.retry();

@@ -439,2 +447,3 @@ });

catch (e) {
this.last_error = e;
this.log('error', 'JSON is invalid');

@@ -445,5 +454,17 @@ return this.cb(e, this.raw, this, this.additional_arguments);

// non-200 status codes
if (this.response.statusCode >= 500) {
this.last_error = {
response: this.raw,
code: this.response.statusCode
};
return this.retry();
}
// non-200 and non-500 status codes
if (this.response.statusCode < 200 || this.response.statusCode >= 300) {
let error = {
this.last_error = {
response: this.raw,

@@ -453,4 +474,3 @@ code: this.response.statusCode

return this.cb(error, null, this, this.additional_arguments);
return this.cb(this.last_error, null, this, this.additional_arguments);
}

@@ -507,3 +527,3 @@

if (~this._retryables.indexOf(err.code) && this.retries < this._max_retry) {
this.errors.push(err);
this.last_error = err;
return this.retry();

@@ -510,0 +530,0 @@ }

{
"name": "cuddle",
"version": "1.2.0",
"version": "1.3.0",
"description": "Cuddle is a minimal, chainable and readability first http client",

@@ -5,0 +5,0 @@ "main": "index.js",

# Cuddle
[![Build Status](https://travis-ci.org/ravenjohn/cuddle.svg?branch=master)](https://travis-ci.org/ravenjohn/cuddle)
[![NPM version](https://img.shields.io/npm/v/cuddle.svg)](https://www.npmjs.com/package/cuddle)
Cuddle is a minimal, chainable, retryable and "readability first" node http client. It's built to use for calling third-party APIs. Just what you need.

@@ -6,0 +8,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc