Skip to content

Commit

Permalink
Fixing an issue of empty JSON bodies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Krulis committed Dec 4, 2017
1 parent fcd1055 commit 387179a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/redux/helpers/api/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ const createFormData = body => {
return data;
};

const encodeBody = (body, method, encodeAsMultipart) => {
if (method.toUpperCase() !== 'POST') {
return undefined;
}

if (encodeAsMultipart) {
return body ? createFormData(body) : undefined;
} else {
// otherwise we encode in JSON
return JSON.stringify(body || []);
}
};

export const createRequest = (
endpoint,
query = {},
Expand All @@ -58,9 +71,7 @@ export const createRequest = (
fetch(getUrl(assembleEndpoint(endpoint, query)), {
method,
headers,
body: body
? uploadFiles ? createFormData(body) : JSON.stringify(body)
: undefined
body: encodeBody(body, method, uploadFiles)
});

export const getHeaders = (headers, accessToken, skipContentType) => {
Expand Down

0 comments on commit 387179a

Please sign in to comment.