Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: swellstores/swell-node
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.0
Choose a base ref
...
head repository: swellstores/swell-node
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.4.1
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Nov 13, 2023

  1. Fix: handle promise rejection in auth stage (#26)

    * handle promise rejection in auth stage
    
    * ensure get always returns a promise
    
    * flushRequestsPending auth happens after outer promise
    swellmike authored Nov 13, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1842398 View commit details
  2. 5.4.1

    swellmike committed Nov 13, 2023
    Copy the full SHA
    5897492 View commit details
Showing with 30 additions and 21 deletions.
  1. +27 −18 lib/client.js
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
45 changes: 27 additions & 18 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -263,7 +263,7 @@ class Client extends EventEmitter {
*/
get(url, data, callback) {
if (!url) {
throw new Error('url is required');
return Promise.reject(new Error('url is required'));
}

if (typeof data === 'function') {
@@ -277,10 +277,8 @@ class Client extends EventEmitter {
}

if (!this.authed) {
return new Promise((resolve) => {
// If not connected, do auth to get updated versions first
this.getPendingAuth(url, data, callback, resolve);
});
// If not connected, do auth to get updated versions first
return this.getPendingAuth(url, data, callback);
}

// Indicates whether to check the request cache or not
@@ -301,22 +299,33 @@ class Client extends EventEmitter {
return this.request('get', url, data, callback);
}

getPendingAuth(url, data, callback, resolve) {
if (this.requestsPendingAuth) {
this.requestsPendingAuth.push({ url, data, callback, resolve });
return;
}
getPendingAuth(url, data, callback) {
return new Promise((resolve, reject) => {
if (this.requestsPendingAuth) {
this.requestsPendingAuth.push({ url, data, callback, resolve });
return;
}

this.requestsPendingAuth = [];
this.requestsPendingAuth = [];

this.authWithKey(() => {
this.get(url, data, (_err, result, headers) => {
if (callback) {
callback(null, result, headers);
}
resolve(result);
});
this.authWithKey(() => {
this.get(url, data, (err, result, headers) => {
if (typeof callback === 'function') {
callback(err, result, headers);
}

if (err) {
reject(err);
return;
}

resolve(result);
})
.catch((err) => {
reject(err.message);
});
});
}).then(() => {
this.flushRequestsPendingAuth();
});
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swell-node",
"version": "5.4.0",
"version": "5.4.1",
"description": "Swell API library for NodeJS",
"engines": {
"node": ">=14.19.1",