Skip to content

Commit

Permalink
Fix executing service bus topic trigger (#3763)
Browse files Browse the repository at this point in the history
* Fix executing service bus topic trigger

* Fix test
  • Loading branch information
alexweininger authored Jul 18, 2023
1 parent cd2e632 commit 7ced659
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@
"@microsoft/vscode-azext-azureutils": "^2.0.1",
"@microsoft/vscode-azext-utils": "^2.0.0",
"@microsoft/vscode-azureresources-api": "^2.0.4",
"cross-fetch": "^4.0.0",
"escape-string-regexp": "^4.0.0",
"extract-zip": "^2.0.1",
"fs-extra": "^4.0.2",
Expand Down
14 changes: 10 additions & 4 deletions src/commands/executeFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { createHttpHeaders } from '@azure/core-rest-pipeline';
import { SiteClient } from '@microsoft/vscode-azext-azureappservice';
import { IActionContext, parseError } from '@microsoft/vscode-azext-utils';
import fetch from 'cross-fetch';
import { window } from 'vscode';
import { FuncVersion } from '../FuncVersion';
import { functionFilter } from '../constants';
Expand Down Expand Up @@ -82,10 +83,15 @@ export async function executeFunction(context: IActionContext, node?: FunctionTr
context.errorHandling.suppressReportIssue = true;
throw new Error(localize('failedToConnect', 'Failed to connect. Make sure your project is [running locally](https://aka.ms/AA76v2d).'));
} else if (errorType === '400') {
// stringify JSON object to match the format in the portal
functionInput = <{}>JSON.stringify(functionInput, undefined, 2);
body = { input: functionInput };
responseText = (await requestUtils.sendRequestWithExtTimeout(context, { method: 'POST', ...triggerRequest, headers, body: JSON.stringify(body) })).bodyAsText;
const response = await fetch(triggerRequest.url, {
method: 'POST',
body: JSON.stringify({
// stringify JSON object to match the format in the portal
input: JSON.stringify(functionInput),
}),
headers: headers.toJSON(),
});
responseText = await response.text();
} else {
context.telemetry.maskEntireErrorMessage = true; // since the response is directly related to the code the user authored themselves
throw error;
Expand Down
4 changes: 2 additions & 2 deletions test/nightly/createProjectAndDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as vscode from 'vscode';
import { copyFunctionUrl, createGenericClient, createNewProjectInternal, deployProductionSlot, FuncVersion, getRandomHexString, nonNullProp } from '../../extension.bundle';
import { addParallelSuite, ParallelTest, runInSeries } from '../addParallelSuite';
import { getTestWorkspaceFolder } from '../global.test';
import { defaultTestFuncVersion, getCSharpValidateOptions, getJavaScriptValidateOptions, getBallerinaValidateOptions, getPowerShellValidateOptions, getPythonValidateOptions, getTypeScriptValidateOptions, IValidateProjectOptions, validateProject } from '../project/validateProject';
import { defaultTestFuncVersion, getBallerinaValidateOptions, getCSharpValidateOptions, getJavaScriptValidateOptions, getPowerShellValidateOptions, getPythonValidateOptions, getTypeScriptValidateOptions, IValidateProjectOptions, validateProject } from '../project/validateProject';
import { getRotatingAuthLevel, getRotatingLocation, getRotatingNodeVersion, getRotatingPythonVersion } from './getRotatingValue';
import { resourceGroupsToDelete } from './global.nightly.test';

Expand Down Expand Up @@ -120,7 +120,7 @@ async function validateFunctionUrl(appName: string, functionName: string, routeP
assert.ok(functionUrl?.includes(routePrefix), `Function url "${functionUrl}" did not include routePrefix "${routePrefix}".`);

const client: ServiceClient = await createGenericClient(await createTestActionContext(), undefined);
const response = await client.sendRequest(createPipelineRequest({ method: 'POST', url: functionUrl!, body: { name: "World" } }));
const response = await client.sendRequest(createPipelineRequest({ method: 'POST', url: functionUrl!, body: JSON.stringify({ name: "World" }) }));
const body: string = nonNullProp(response, 'bodyAsText');
assert.ok((body.includes('Hello') && body.includes('World')) || body.includes('Welcome'), 'Expected function response to include "Hello World" or "Welcome"');
}

0 comments on commit 7ced659

Please sign in to comment.