@vouchfor/sdk 1.1.34 → 1.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/services/baseService.js +17 -4
- package/lib/shared/tasks.js +2 -2
- package/lib/shared/utils.js +1 -1
- package/package.json +1 -1
|
@@ -108,14 +108,27 @@ class BaseService {
|
|
|
108
108
|
method,
|
|
109
109
|
url,
|
|
110
110
|
logger: this._logger
|
|
111
|
+
}).then((res) => {
|
|
112
|
+
if (task.id && res.task !== task.id) {
|
|
113
|
+
tasks.cancel(task.id); // our callback url was ignored
|
|
114
|
+
}
|
|
115
|
+
return res;
|
|
116
|
+
}).catch((err) => {
|
|
117
|
+
return { error: err }
|
|
111
118
|
}),
|
|
112
119
|
task.promise || {}
|
|
113
120
|
]);
|
|
114
121
|
|
|
115
|
-
if (
|
|
116
|
-
res
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
if (task.id) {
|
|
123
|
+
if (res.task === task.id) {
|
|
124
|
+
res = cb.json; // we got the async response we expected
|
|
125
|
+
} else if (res.error && cb.json) {
|
|
126
|
+
res = cb.json; // api gateway failed, use async response
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (res.error) {
|
|
131
|
+
throw res.error;
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
return res;
|
package/lib/shared/tasks.js
CHANGED
|
@@ -27,7 +27,7 @@ class TaskBroker {
|
|
|
27
27
|
const timeout = setTimeout(() => {
|
|
28
28
|
if (!this.pending.has(id)) return;
|
|
29
29
|
this.pending.delete(id);
|
|
30
|
-
rejectFn(
|
|
30
|
+
rejectFn({ status: 0, json: { error: 'TimedOut' } });
|
|
31
31
|
}, timeoutMs);
|
|
32
32
|
|
|
33
33
|
this.pending.set(id, {
|
|
@@ -49,7 +49,7 @@ class TaskBroker {
|
|
|
49
49
|
cancel(id) {
|
|
50
50
|
const entry = this.pending.get(id);
|
|
51
51
|
if (!entry) return false;
|
|
52
|
-
entry.
|
|
52
|
+
entry.resolve({ status: 0, json: { error: 'Cancelled' } });
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
55
|
|
package/lib/shared/utils.js
CHANGED