@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.
@@ -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 (res.task === task.id && task.id) {
116
- res = cb.json; // we got the async response we expected
117
- } else {
118
- tasks.cancel(task.id); // our callback url was ignored
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;
@@ -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(new Error(`Timed out waiting for ${id}`));
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.reject({ status: 0, json: 'cancelled' });
52
+ entry.resolve({ status: 0, json: { error: 'Cancelled' } });
53
53
  return true;
54
54
  }
55
55
 
@@ -108,7 +108,7 @@ module.exports = {
108
108
 
109
109
  const errors = [
110
110
  502, // bad gateway, the BE is deploying
111
- 504, // gatewat timeout, the BE will scale
111
+ //504 gateway timeout, do not retry!!
112
112
  ];
113
113
  const maxAttempts = 8;
114
114
  const interval = 1000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/sdk",
3
- "version": "1.1.34",
3
+ "version": "1.1.35",
4
4
  "description": "Vouch API SDK",
5
5
  "main": "lib/index.js",
6
6
  "repository": {