Skip to content

Commit

Permalink
fix: do JSON.parse for requestBody (issue #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo6104 committed Feb 5, 2021
1 parent 7f044dd commit 387f2b6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions dist/esm/httpRequester.js

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

2 changes: 1 addition & 1 deletion dist/esm/httpRequester.js.map

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

8 changes: 8 additions & 0 deletions dist/plugin.js

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

2 changes: 1 addition & 1 deletion dist/plugin.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/httpRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class HttpRequester implements Http.Requester {
}

public request(verb: Http.Verb, url: string, callbackOrRequestBody: Callback<Http.Response> | string, callback?: Callback<Http.Response>): void {
var requestBody: string;
var requestBody: any;
var requestCallback: Callback<Http.Response> = callback!;

// request(verb, url, callback)
Expand All @@ -28,6 +28,14 @@ export class HttpRequester implements Http.Requester {
requestBody = <string>callbackOrRequestBody;
}

if (typeof requestBody === "string") {
try {
requestBody = JSON.parse(requestBody); // if it is stringify JSON string, parse
} catch (e) {
// do nothing
}
}

var methodName = this.getHttpMethodName(verb);
if (methodName === null) {
return requestCallback(new Error("Method Not Allowed"), null);
Expand Down

0 comments on commit 387f2b6

Please sign in to comment.