Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
* properly handle calls where the server is not returning any content…
Browse files Browse the repository at this point in the history
… - typically a DELETE

* no need for token when deleting a demo.
#107
  • Loading branch information
Frederic Lavigne committed Jan 27, 2017
1 parent 7879bc3 commit 69444ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/modules/demos.js
Expand Up @@ -175,7 +175,7 @@ export function *watchEndDemoSession() {
yield take(END_DEMO_SESSION);
const demoState = yield select(demoSelector);
try {
yield call(api.endDemo, demoState.guid, demoState.token);
yield call(api.endDemo, demoState.guid);
}
catch (error) {
console.log('Error during logout', error);
Expand Down
10 changes: 7 additions & 3 deletions src/services/index.js
Expand Up @@ -11,7 +11,12 @@ export const callApi = (endpoint, {
method,
body: JSON.stringify(body),
})
.then(response => response.json().then(json => ({ json, response })))
.then(response => {
if (response.status === 204) { // good response but no content
return { json: { status: 204, statusText: 'no content' }, response };
}
return response.json().then(json => ({ json, response }));
})
.then(({ json, response }) => {
if (!response.ok) {
console.log(`Error calling URL : ${apiUrl}`);
Expand All @@ -28,9 +33,8 @@ export const createDemo = () =>

export const getDemo = guid => callApi(`demos/${guid}`);

export const endDemo = (guid, token) =>
export const endDemo = (guid) =>
callApi(`demos/${guid}`, {
headers: { Authorization: `Bearer ${token}` },
method: 'DELETE',
});

Expand Down

0 comments on commit 69444ab

Please sign in to comment.