@sap-ux/axios-extension 1.2.2 → 1.2.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.
@@ -47,7 +47,7 @@ export declare function prettyPrintMessage({ msg, log, host }: {
47
47
  host?: string;
48
48
  }): void;
49
49
  /**
50
- * Log a Gateway error.
50
+ * Log Gateway errors returned from the S_MGW_ODATA_INNER_ERROR table which is a store of OData Inner Error data.
51
51
  *
52
52
  * @param options options
53
53
  * @param options.error error message returned from gateway
@@ -67,7 +67,7 @@ function logFullURL({ host, path, log }) {
67
67
  }
68
68
  }
69
69
  /**
70
- * Log a Gateway error.
70
+ * Log Gateway errors returned from the S_MGW_ODATA_INNER_ERROR table which is a store of OData Inner Error data.
71
71
  *
72
72
  * @param options options
73
73
  * @param options.error error message returned from gateway
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import type { AxiosResponse, AxiosRequestConfig } from 'axios';
4
+ import type { ErrorMessage } from './message';
4
5
  import { ODataService } from '../base/odata-service';
5
6
  /**
6
7
  * Required configuration for the BSP hosting an app.
@@ -159,5 +160,12 @@ export declare class Ui5AbapRepositoryService extends ODataService {
159
160
  error: Error;
160
161
  host?: string;
161
162
  }): void;
163
+ /**
164
+ * Get ErrorMessage object from response contain an error as a string.
165
+ *
166
+ * @param data string value
167
+ * @returns undefined if an error object is not found or populated ErrorMessage object
168
+ */
169
+ protected getErrorMessageFromString(data: string): ErrorMessage | undefined;
162
170
  }
163
171
  //# sourceMappingURL=ui5-abap-repository-service.d.ts.map
@@ -60,14 +60,18 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
60
60
  * @returns application information or undefined
61
61
  */
62
62
  getInfo(app) {
63
+ var _a;
63
64
  return __awaiter(this, void 0, void 0, function* () {
64
65
  try {
65
66
  const response = yield this.get(`/Repositories('${encodeURIComponent(app)}')`);
66
67
  return response.odata();
67
68
  }
68
69
  catch (error) {
69
- this.log.debug(`Retrieving application ${app}, error found ${error}`);
70
- return undefined;
70
+ this.log.debug(`Retrieving application ${app}, ${error}`);
71
+ if ((0, odata_request_error_1.isAxiosError)(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
72
+ return undefined;
73
+ }
74
+ throw error;
71
75
  }
72
76
  });
73
77
  }
@@ -95,12 +99,21 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
95
99
  if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a['sap-message']) {
96
100
  (0, message_1.prettyPrintMessage)({ msg: response.headers['sap-message'], log: this.log, host: frontendUrl });
97
101
  }
98
- // log url of created/updated app
99
- const path = '/sap/bc/ui5_ui5' + (!bsp.name.startsWith('/') ? '/sap/' : '') + bsp.name.toLowerCase();
100
- const query = ((_b = this.defaults.params) === null || _b === void 0 ? void 0 : _b['sap-client'])
101
- ? '?sap-client=' + this.defaults.params['sap-client']
102
- : '';
103
- this.log.info(`App available at ${frontendUrl}${path}${query}`);
102
+ if (!testMode) {
103
+ // log url of created/updated app
104
+ const path = '/sap/bc/ui5_ui5' + (!bsp.name.startsWith('/') ? '/sap/' : '') + bsp.name.toLowerCase();
105
+ const query = ((_b = this.defaults.params) === null || _b === void 0 ? void 0 : _b['sap-client'])
106
+ ? '?sap-client=' + this.defaults.params['sap-client']
107
+ : '';
108
+ this.log.info(`App available at ${frontendUrl}${path}${query}`);
109
+ }
110
+ else {
111
+ (0, message_1.prettyPrintError)({
112
+ error: this.getErrorMessageFromString(response === null || response === void 0 ? void 0 : response.data),
113
+ log: this.log,
114
+ host: frontendUrl
115
+ });
116
+ }
104
117
  return response;
105
118
  }
106
119
  catch (error) {
@@ -256,7 +269,8 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
256
269
  }
257
270
  }
258
271
  catch (error) {
259
- if (((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) === 504) {
272
+ // Known ABAP timeout exception codes should re-trigger a deployment again to confirm the app was deployed
273
+ if ([504, 408].includes((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status)) {
260
274
  // Kill the flow after three attempts
261
275
  if (tryCount >= 3) {
262
276
  throw error;
@@ -312,26 +326,39 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
312
326
  * @param e.host hostname
313
327
  */
314
328
  logError({ error, host }) {
315
- var _a;
329
+ var _a, _b;
316
330
  this.log.error(error.message);
317
331
  if ((0, odata_request_error_1.isAxiosError)(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data)) {
318
- let responseData = error.response.data;
319
- if (typeof error.response.data === 'string') {
320
- try {
321
- responseData = JSON.parse(error.response.data);
322
- }
323
- catch (_b) {
324
- // Not much we can do!
325
- }
326
- }
327
- if (responseData === null || responseData === void 0 ? void 0 : responseData['error']) {
328
- (0, message_1.prettyPrintError)({ error: responseData['error'], host, log: this.log });
332
+ const errorMessage = this.getErrorMessageFromString((_b = error.response) === null || _b === void 0 ? void 0 : _b.data);
333
+ if (errorMessage) {
334
+ (0, message_1.prettyPrintError)({ error: errorMessage, host, log: this.log });
329
335
  }
330
336
  else {
331
337
  this.log.error(error.response.data);
332
338
  }
333
339
  }
334
340
  }
341
+ /**
342
+ * Get ErrorMessage object from response contain an error as a string.
343
+ *
344
+ * @param data string value
345
+ * @returns undefined if an error object is not found or populated ErrorMessage object
346
+ */
347
+ getErrorMessageFromString(data) {
348
+ let error;
349
+ if (typeof data === 'string') {
350
+ try {
351
+ const errorMsg = JSON.parse(data);
352
+ if (errorMsg.error) {
353
+ error = errorMsg.error;
354
+ }
355
+ }
356
+ catch (_a) {
357
+ // Not much we can do!
358
+ }
359
+ }
360
+ return error;
361
+ }
335
362
  }
336
363
  exports.Ui5AbapRepositoryService = Ui5AbapRepositoryService;
337
364
  Ui5AbapRepositoryService.PATH = '/sap/opu/odata/UI5/ABAP_REPOSITORY_SRV';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/axios-extension",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Extension of the Axios module adding convinience methods to interact with SAP systems especially with OData services.",
5
5
  "repository": {
6
6
  "type": "git",