@sap-ux/odata-service-inquirer 2.2.29 → 2.2.30

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.
@@ -183,12 +183,17 @@ export declare class ConnectionValidator {
183
183
  */
184
184
  private createSystemConnection;
185
185
  /**
186
- * Check if we should attempt to use the v4 catalog service as a fallback.
186
+ * Determine if a v4 catalog request should be made based on the specified error and if the error originated from a v2 or v4 catalog request.
187
+ * If the error originated from a v2 catalog request and it is of type 401/403/404 then we try the v4 catalog.
188
+ * If the v4 catalog request fails, for any reason, and the v2 catalog request failed with 401/403 we will throw that (401/403) error,
189
+ * ultimately resulting in a basic auth prompt for the end-user.
190
+ * Otherwise the v4 catalog request error is thrown, which may also be a 401/403, again resulting in a basic auth prompt and re-validation.
191
+ * If both catalogs have returned 404 nothing else can be done, the error is thrown and reported.
187
192
  *
188
- * @param statusCode http status code, if not provided will return false as we cannot determine the reason for v2 catalog request failure
189
- * @returns true if we should attempt the v4 catalog service
193
+ * @param error - an error returned from either a v2 or v4 catalog listServices request.
194
+ * @param v4Requested - has the v4 catalog been requested
190
195
  */
191
- private shouldAttemptV4Catalog;
196
+ private handleCatalogError;
192
197
  /**
193
198
  * Callback for when the Abap cloud system refresh token changes.
194
199
  *
@@ -338,32 +338,43 @@ class ConnectionValidator {
338
338
  }
339
339
  }
340
340
  catch (error) {
341
- // We will try the v4 catalog if v2 returns a 404 or an auth code. Try the v4 catalog with the credentials provided also
342
- // as the user may not be authorized for the v2 catalog specifically.
343
- if (this._catalogV4 &&
344
- !v4Requested &&
345
- this.shouldAttemptV4Catalog(error.response?.status)) {
346
- await this._catalogV4.listServices();
347
- }
348
- else {
349
- // Either the v2 or v4 catalog request failed for a specific odata version, or both failed where no odata verison was specified
350
- // Do some root cause analysis to determine the end user help message
351
- throw error;
352
- }
341
+ await this.handleCatalogError(error, v4Requested);
353
342
  }
354
343
  }
355
344
  /**
356
- * Check if we should attempt to use the v4 catalog service as a fallback.
345
+ * Determine if a v4 catalog request should be made based on the specified error and if the error originated from a v2 or v4 catalog request.
346
+ * If the error originated from a v2 catalog request and it is of type 401/403/404 then we try the v4 catalog.
347
+ * If the v4 catalog request fails, for any reason, and the v2 catalog request failed with 401/403 we will throw that (401/403) error,
348
+ * ultimately resulting in a basic auth prompt for the end-user.
349
+ * Otherwise the v4 catalog request error is thrown, which may also be a 401/403, again resulting in a basic auth prompt and re-validation.
350
+ * If both catalogs have returned 404 nothing else can be done, the error is thrown and reported.
357
351
  *
358
- * @param statusCode http status code, if not provided will return false as we cannot determine the reason for v2 catalog request failure
359
- * @returns true if we should attempt the v4 catalog service
352
+ * @param error - an error returned from either a v2 or v4 catalog listServices request.
353
+ * @param v4Requested - has the v4 catalog been requested
360
354
  */
361
- shouldAttemptV4Catalog(statusCode) {
362
- if (!statusCode) {
363
- return false;
355
+ async handleCatalogError(error, v4Requested) {
356
+ const statusCode = error.response?.status;
357
+ const errorType = statusCode ? inquirer_common_1.ErrorHandler.getErrorType(statusCode) : undefined;
358
+ // Try the v4 catalog with the credentials provided
359
+ // as the user may not be authorized for the v2 catalog specifically.
360
+ const shouldFallbackToV4 = statusCode && !v4Requested && (errorType === inquirer_common_1.ERROR_TYPE.NOT_FOUND || errorType === inquirer_common_1.ERROR_TYPE.AUTH);
361
+ if (this._catalogV4 && shouldFallbackToV4) {
362
+ try {
363
+ await this._catalogV4.listServices();
364
+ }
365
+ catch (v4Error) {
366
+ // if original error was of type auth, throw it so the consumer can handle it accordingly e.g show basic auth prompts
367
+ if (errorType === inquirer_common_1.ERROR_TYPE.AUTH) {
368
+ throw error;
369
+ }
370
+ throw v4Error;
371
+ }
372
+ }
373
+ else {
374
+ // Either the v2 or v4 catalog request failed for a specific odata version, or both failed where no odata verison was specified
375
+ // Do some root cause analysis to determine the end user help message
376
+ throw error;
364
377
  }
365
- const errorType = inquirer_common_1.ErrorHandler.getErrorType(statusCode);
366
- return errorType === inquirer_common_1.ERROR_TYPE.NOT_FOUND || errorType === inquirer_common_1.ERROR_TYPE.AUTH;
367
378
  }
368
379
  /**
369
380
  * Callback for when the Abap cloud system refresh token changes.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/odata-service-inquirer",
3
3
  "description": "Prompts module that can prompt users for inputs required for odata service writing",
4
- "version": "2.2.29",
4
+ "version": "2.2.30",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",