Skip to content

Commit

Permalink
fix(Designer): Only resolve app settings if they are used in resource…
Browse files Browse the repository at this point in the history
… ids (#4354)

* Only resolve app settings if they are used in subscription ids

* Only resolving app settings in resource ids
  • Loading branch information
rllyy97 committed Mar 13, 2024
1 parent b4e0212 commit 04b6f29
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export class WorkflowUtility {
if (appsettings) {
for (const settingName of Object.keys(appsettings)) {
const settingValue = appsettings[settingName] !== undefined ? appsettings[settingName] : '';
result = replaceAllOccurrences(result, `@appsetting('${settingName}')`, settingValue);
result = replaceAllOccurrences(result, `@{appsetting('${settingName}')}`, settingValue);
result = replaceOccurrenceInResourceIds(result, `@appsetting('${settingName}')`, settingValue);
result = replaceOccurrenceInResourceIds(result, `@{appsetting('${settingName}')}`, settingValue);
}
}

Expand Down Expand Up @@ -116,3 +116,21 @@ function replaceIfFoundAndVerifyJson(stringifiedJson: string, searchValue: strin
return undefined;
}
}

function replaceOccurrenceInResourceIds(_inputString: string, settingName: string, settingValue: string): string {
let inputString = _inputString;
const resourceIdRegex = /\/subscriptions\/[^"]+"/g;
const resourceIds = inputString.match(resourceIdRegex);

// If no resource ids are found, return the original string
if (!resourceIds) return inputString;

for (const resourceId of resourceIds) {
if (resourceId.includes(settingName)) {
const replacedString = resourceId.replace(settingName, settingValue);
// Replace the original resource id in the input string with the replaced string
inputString = inputString.replace(resourceId, replacedString);
}
}
return inputString;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
aggregate,
equals,
getRecordEntry,
parseErrorMessage,
} from '@microsoft/logic-apps-shared';
import type { InputParameter, OutputParameter, LogicAppsV2, OperationManifest } from '@microsoft/logic-apps-shared';
import type { Dispatch } from '@reduxjs/toolkit';
Expand Down Expand Up @@ -276,7 +277,8 @@ export const initializeOperationDetailsForManifest = async (
...childGraphInputs,
];
} catch (error: any) {
const message = `Unable to initialize operation details for operation - ${nodeId}. Error details - ${error}`;
const errorMessage = parseErrorMessage(error);
const message = `Unable to initialize operation details for operation - ${nodeId}. Error details - ${errorMessage}`;
LoggerService().log({
level: LogEntryLevel.Error,
area: 'operation deserializer',
Expand Down
8 changes: 2 additions & 6 deletions libs/designer/src/lib/core/utils/swagger/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
isDynamicSchemaExtension,
isTemplateExpression,
map,
parseErrorMessage,
parsePathnameAndQueryKeyFromUri,
removeConnectionPrefix,
startsWith,
Expand Down Expand Up @@ -124,12 +125,7 @@ export const initializeOperationDetailsForSwagger = async (

throw new Error('Operation info could not be found for a swagger operation');
} catch (error: any) {
let errorString = '';
try {
errorString = error?.toString() ?? error;
} catch (_: any) {
errorString = 'Could not convert error to string';
}
const errorString = parseErrorMessage(error);
const message = `Unable to initialize operation details for swagger based operation - ${nodeId}. Error details - ${errorString}`;
LoggerService().log({
level: LogEntryLevel.Error,
Expand Down
18 changes: 11 additions & 7 deletions libs/logic-apps-shared/src/utils/src/lib/helpers/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ export const HTTP_METHODS = {
} as const;

export const parseErrorMessage = (error: any, defaultErrorMessage?: string): string => {
let message = error?.message ?? error?.Message ?? error?.error?.message ?? error?.content?.message ?? undefined;
if (message) return message;
try {
let message = error?.message ?? error?.Message ?? error?.error?.message ?? error?.content?.message ?? undefined;
if (message) return message;

// Response text needs to be parsed to get internal error message
if (error?.responseText) {
message = parseErrorMessage(JSON.parse(error.responseText), defaultErrorMessage);
}
// Response text needs to be parsed to get internal error message
if (error?.responseText) {
message = parseErrorMessage(JSON.parse(error.responseText), defaultErrorMessage);
}

return message ?? defaultErrorMessage ?? 'Unknown error';
return message ?? defaultErrorMessage ?? error ?? 'Unknown error';
} catch (e) {
return 'Could not parse error message.';
}
};

0 comments on commit 04b6f29

Please sign in to comment.