Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 4027a75

Browse files
committed
Avoid double callback if success callback errors
1 parent 8555c7f commit 4027a75

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22
- [FIXED] Parsing of max-age from Set-Cookie headers.
3+
- [FIXED] Double callback if plugin errors when updating state.
34

45
# 4.3.1 (2021-03-17)
56
- [NEW] Add migration guide to the newly supported cloudant-node-sdk

plugins/cookieauth.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2015, 2019 IBM Corp. All rights reserved.
1+
// Copyright © 2015, 2021 IBM Corp. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -68,16 +68,13 @@ class CookiePlugin extends BasePlugin {
6868
delete req.url;
6969
req.uri = u.format(new u.URL(req.uri), {auth: false});
7070

71-
self._tokenManager.renewIfRequired().then(() => {
72-
callback(state);
73-
}).catch((error) => {
71+
self._tokenManager.renewIfRequired().catch((error) => {
7472
if (state.attempt < state.maxAttempt) {
7573
state.retry = true;
7674
} else {
7775
state.abortWithResponse = [ error ]; // return error to client
7876
}
79-
callback(state);
80-
});
77+
}).finally(() => callback(state));
8178
}
8279

8380
onResponse(state, response, callback) {

plugins/iamauth.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017, 2019 IBM Corp. All rights reserved.
1+
// Copyright © 2017, 2021 IBM Corp. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -66,9 +66,7 @@ class IAMPlugin extends BasePlugin {
6666
delete req.url;
6767
req.uri = u.format(new u.URL(req.uri), {auth: false});
6868

69-
self._tokenManager.renewIfRequired().then(() => {
70-
callback(state);
71-
}).catch((error) => {
69+
self._tokenManager.renewIfRequired().catch((error) => {
7270
debug(error);
7371
if (state.attempt < state.maxAttempt) {
7472
state.retry = true;
@@ -85,8 +83,7 @@ class IAMPlugin extends BasePlugin {
8583
} else {
8684
state.abortWithResponse = [ error ]; // return error to client
8785
}
88-
callback(state);
89-
});
86+
}).finally(() => callback(state));
9087
}
9188

9289
onResponse(state, response, callback) {

0 commit comments

Comments
 (0)