Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix executing service bus topic trigger #3763

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stringify the stringify, ehh?

// 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"');
}