Skip to content

Commit

Permalink
Better handle empty POST and publish payloads (#123)
Browse files Browse the repository at this point in the history
* Tweak handling of empty payloads.

* Update CHANGELOG.
  • Loading branch information
philliphoff authored Sep 3, 2020
1 parent d9109c4 commit e63c627
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Change Log

## v0.3.0 - 02 September 2020
## v0.3.0 - 03 September 2020

A collection of accumulated fixes and minor enhancements.

### Fixed

* Pop up an error when invoking (POST) application method with an empty payload [#121](https://github.com/microsoft/vscode-dapr/issues/121)
* Pop up an error "Request failed with status code 404" when publishing message [#117](https://github.com/microsoft/vscode-dapr/issues/117)
* The default value of the port is "app" when invoking "Dapr: Scaffold Dapr Tasks" command [#109](https://github.com/microsoft/vscode-dapr/issues/109)
* It shows "Failed to load message bundle..." after expanding "APPLICATIONS" [#104](https://github.com/microsoft/vscode-dapr/issues/104)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/applications/invokeCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function getPayload(context: ITelemetryContext, ui: UserInput, work
value: previousPayloadString
});

const payload = (payloadString && <unknown>JSON.parse(payloadString)) || undefined;
const payload = payloadString ? <unknown>JSON.parse(payloadString) : undefined;

await workspaceState.update(payLoadStateKey, payloadString);

Expand Down
10 changes: 6 additions & 4 deletions src/services/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ export default class AxiosHttpClient implements HttpClient {

const config = createConfig(options?.allowRedirects, cancelTokenSource.token);

config.headers = {
'content-type': options?.json ? 'application/json' : undefined
};
if (data !== undefined) {
config.headers = {
'content-type': options?.json ? 'application/json' : undefined
};
}

try {
const response = await axios.post<unknown>(
url,
options?.json ? JSON.stringify(data) : data,
(data !== undefined && options?.json) ? JSON.stringify(data) : data,
config);

return { data: response.data, headers: <{[key: string]: string}>response.headers, status: response.status };
Expand Down

0 comments on commit e63c627

Please sign in to comment.