@google-cloud/nodejs-common 1.5.6-beta → 1.5.7-beta

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google-cloud/nodejs-common",
3
- "version": "1.5.6-beta",
3
+ "version": "1.5.7-beta",
4
4
  "description": "A NodeJs common library for solutions based on Cloud Functions",
5
5
  "author": "Google Inc.",
6
6
  "license": "Apache-2.0",
@@ -123,34 +123,47 @@ class MeasurementProtocolGA4 {
123
123
  let retriedTimes = 0;
124
124
  let response;
125
125
  while (retriedTimes <= RETRY_TIMES) {
126
- response = await request(requestOptions);
127
- if (response.status < 500) break; // Only retry when server errors.
128
- this.logger.warn('Got an 5XX error', response);
126
+ try {
127
+ response = await request(requestOptions);
128
+ if (response.status < 500) break; // Only retry when server errors.
129
+ this.logger.warn('Got a 5XX error', response);
130
+ } catch (error) {
131
+ this.logger.warn('Got an error', error);
132
+ if (retriedTimes === RETRY_TIMES) {
133
+ this.logger.error('Maximum retry times exceeded.');
134
+ batchResult.result = false;
135
+ batchResult.errors = [error.toString()];
136
+ break;
137
+ }
138
+ }
129
139
  retriedTimes++;
130
140
  await wait(retriedTimes * 1000);
141
+ this.logger.warn('Will retry now...');
131
142
  };
132
- this.logger.debug('Configuration:', config);
133
- this.logger.debug('Input Data: ', lines);
134
- this.logger.debug(`Batch[${batchId}] status: ${response.status}`);
135
- this.logger.debug(response.data);
136
- // There is not enough information from the non-debug mode.
137
- if (!this.debugMode) {
138
- if (response.status >= 200 && response.status < 300) {
139
- batchResult.result = true;
140
- } else {
141
- batchResult.result = false;
142
- const errorMessage =
143
- `MP GA4 [${batchId}] http status ${response.status}.`;
144
- this.logger.error(errorMessage, line);
145
- batchResult.errors = [errorMessage];
146
- }
147
- } else {
148
- if (response.data.validationMessages.length === 0) {
149
- batchResult.result = true;
143
+ if (response) {
144
+ this.logger.debug('Configuration:', config);
145
+ this.logger.debug('Input Data: ', lines);
146
+ this.logger.debug(`Batch[${batchId}] status: ${response.status}`);
147
+ this.logger.debug(response.data);
148
+ // There is not enough information from the non-debug mode.
149
+ if (!this.debugMode) {
150
+ if (response.status >= 200 && response.status < 300) {
151
+ batchResult.result = true;
152
+ } else {
153
+ batchResult.result = false;
154
+ const errorMessage =
155
+ `MP GA4 [${batchId}] http status ${response.status}.`;
156
+ this.logger.error(errorMessage, line);
157
+ batchResult.errors = [errorMessage];
158
+ }
150
159
  } else {
151
- batchResult.result = false;
152
- batchResult.errors = response.data.validationMessages.map(
153
- ({ description }) => description);
160
+ if (response.data.validationMessages.length === 0) {
161
+ batchResult.result = true;
162
+ } else {
163
+ batchResult.result = false;
164
+ batchResult.errors = response.data.validationMessages.map(
165
+ ({ description }) => description);
166
+ }
154
167
  }
155
168
  }
156
169
  if (!batchResult.result) {