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: Send proper request body type for code snippets #1639

Merged
merged 5 commits into from
Apr 12, 2022
Merged
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions src/app/services/actions/snippet-action-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function getSnippetPending(): any {
export function getSnippet(language: string): Function {
return async (dispatch: Function, getState: Function) => {
const { devxApi, sampleQuery } = getState();
let body: string = '';

try {
let snippetsUrl = `${devxApi.baseUrl}/api/graphexplorersnippets`;

Expand All @@ -56,13 +58,17 @@ export function getSnippet(language: string): Function {

const requestBody =
sampleQuery.sampleBody &&
Object.keys(sampleQuery.sampleBody).length !== 0 && // check if empty object
sampleQuery.sampleBody.trim() !== ''
Object.keys(sampleQuery.sampleBody).length !== 0
? JSON.stringify(sampleQuery.sampleBody)
: '';

// eslint-disable-next-line max-len
const body = `${sampleQuery.selectedVerb} /${queryVersion}/${requestUrl + search} HTTP/1.1\r\nHost: graph.microsoft.com\r\nContent-Type: application/json\r\n\r\n${requestBody}`;
if(sampleQuery.selectedVerb === 'GET'){
// eslint-disable-next-line max-len
body = `${sampleQuery.selectedVerb} /${queryVersion}/${requestUrl + search} HTTP/1.1\r\nHost: graph.microsoft.com\r\nContent-Type: application/json\r\n\r\n`;
} else {
// eslint-disable-next-line max-len
body = `${sampleQuery.selectedVerb} /${queryVersion}/${requestUrl + search} HTTP/1.1\r\nHost: graph.microsoft.com\r\nContent-Type: application/json\r\n\r\n${requestBody}`;
}
ElinorW marked this conversation as resolved.
Show resolved Hide resolved

const options: IRequestOptions = { method, headers, body };
const obj: any = {};
Expand Down