@cubejs-client/core 1.3.1 → 1.3.3

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/index.d.ts CHANGED
@@ -23,6 +23,10 @@ declare module '@cubejs-client/core' {
23
23
  headers?: Record<string, string>;
24
24
  credentials?: 'omit' | 'same-origin' | 'include';
25
25
  method?: 'GET' | 'PUT' | 'POST' | 'PATCH';
26
+ /**
27
+ * Fetch timeout in milliseconds. Would be passed as AbortSignal.timeout()
28
+ */
29
+ fetchTimeout?: number;
26
30
  };
27
31
 
28
32
  export interface ITransportResponse<R> {
@@ -81,6 +85,10 @@ declare module '@cubejs-client/core' {
81
85
  parseDateMeasures?: boolean;
82
86
  resType?: 'default' | 'compact';
83
87
  castNumerics?: boolean;
88
+ /**
89
+ * How many network errors would be retried before returning to users. Default to 0.
90
+ */
91
+ networkErrorRetries?: number;
84
92
  };
85
93
 
86
94
  export type LoadMethodOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubejs-client/core",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "engines": {},
5
5
  "repository": {
6
6
  "type": "git",
@@ -55,5 +55,5 @@
55
55
  ],
56
56
  "coverageDirectory": "coverage/"
57
57
  },
58
- "gitHead": "78a557da3d86bc40416ced7d034ba829c55ad187"
58
+ "gitHead": "e033d8917c7b9ff89329edc5d0c4fc4cc74c6bf4"
59
59
  }
@@ -2,12 +2,13 @@ import fetch from 'cross-fetch';
2
2
  import 'url-search-params-polyfill';
3
3
 
4
4
  class HttpTransport {
5
- constructor({ authorization, apiUrl, method, headers = {}, credentials }) {
5
+ constructor({ authorization, apiUrl, method, headers = {}, credentials, fetchTimeout }) {
6
6
  this.authorization = authorization;
7
7
  this.apiUrl = apiUrl;
8
8
  this.method = method;
9
9
  this.headers = headers;
10
10
  this.credentials = credentials;
11
+ this.fetchTimeout = fetchTimeout;
11
12
  }
12
13
 
13
14
  request(method, { baseRequestId, ...params }) {
@@ -36,7 +37,8 @@ class HttpTransport {
36
37
  ...this.headers
37
38
  },
38
39
  credentials: this.credentials,
39
- body: requestMethod === 'POST' ? JSON.stringify(params) : null
40
+ body: requestMethod === 'POST' ? JSON.stringify(params) : null,
41
+ signal: this.fetchTimeout ? AbortSignal.timeout(this.fetchTimeout) : undefined,
40
42
  });
41
43
 
42
44
  return {
package/src/index.js CHANGED
@@ -57,6 +57,7 @@ class CubeApi {
57
57
  this.pollInterval = options.pollInterval || 5;
58
58
  this.parseDateMeasures = options.parseDateMeasures;
59
59
  this.castNumerics = typeof options.castNumerics === 'boolean' ? options.castNumerics : false;
60
+ this.networkErrorRetries = options.networkErrorRetries || 0;
60
61
 
61
62
  this.updateAuthorizationPromise = null;
62
63
  }
@@ -104,6 +105,8 @@ class CubeApi {
104
105
  }
105
106
  };
106
107
 
108
+ let networkRetries = this.networkErrorRetries;
109
+
107
110
  const loadImpl = async (response, next) => {
108
111
  const requestInstance = await requestPromise;
109
112
 
@@ -135,7 +138,11 @@ class CubeApi {
135
138
 
136
139
  skipAuthorizationUpdate = false;
137
140
 
138
- if (response.status === 502) {
141
+ if (response.status === 502 ||
142
+ response.error &&
143
+ response.error.toLowerCase() === 'network error' &&
144
+ --networkRetries >= 0
145
+ ) {
139
146
  await checkMutex();
140
147
  return continueWait(true);
141
148
  }