Skip to content

Commit

Permalink
replace request library for superagent
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Vieira <[email protected]>
  • Loading branch information
Bruno Vieira committed Jan 18, 2024
1 parent af6272e commit adcbb17
Show file tree
Hide file tree
Showing 11 changed files with 394 additions and 86 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning].
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html

## [3.2.2] - 2023-01-28
- Remove the `requests` library and use `superagent` instead

## [3.2.1] - 2023-12-20
- Fix missing `customer_uuid` when creating a note or retrieving all notes from a customer

Expand Down
14 changes: 11 additions & 3 deletions lib/chartmogul/util/retry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const request = require('request');
const superagent = require('superagent');
const retry = require('retry');
const { URL } = require('url');

function retryOnStatus (res) {
if (
Expand Down Expand Up @@ -42,12 +43,19 @@ module.exports = function retryRequest (retries, options, cb) {
minTimeout: 500,
maxTimeout: 60 * 1000
});

operation.attempt(function (currentAttempt) {
request(options, (err, res, body) => {
const requestUrl = new URL(options.uri, options.baseUrl).toString();
const request = superagent(options.method || 'get', requestUrl)
.auth(options.auth.user, options.auth.pass)
.set(options.headers)
.send(options.body);

request.end((err, res) => {
if (operation.retry(retryOnStatus(res) || retryOnNetworkError(err))) {
return;
}
cb(err, res, body);
cb(err, res, res && res.body);
});
});
};
Loading

0 comments on commit adcbb17

Please sign in to comment.