Skip to content

Commit

Permalink
Fix: Send proper request body type for code snippets (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElinorW authored Apr 12, 2022
1 parent 1899adf commit 422a95a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/app/services/actions/snippet-action-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function getSnippetPending(): any {
export function getSnippet(language: string): Function {
return async (dispatch: Function, getState: Function) => {
const { devxApi, sampleQuery } = getState();

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

Expand All @@ -56,13 +57,19 @@ 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)
: '';

const httpVersion = 'HTTP/1.1';
const host = 'Host: graph.microsoft.com';
const sampleHeaders = 'Content-Type: application/json';

// 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}`;
let body = `${sampleQuery.selectedVerb} /${queryVersion}/${requestUrl + search} ${httpVersion}\r\n${host}\r\n${sampleHeaders}\r\n\r\n`;
if(sampleQuery.selectedVerb !== 'GET'){
body += `${requestBody}`;
}

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

0 comments on commit 422a95a

Please sign in to comment.