From 69444abe6e2209c88856a586a0aef991bc6c1efd Mon Sep 17 00:00:00 2001 From: Frederic Lavigne Date: Fri, 27 Jan 2017 10:43:27 +0100 Subject: [PATCH] * properly handle calls where the server is not returning any content - typically a DELETE * no need for token when deleting a demo. https://github.com/IBM-Bluemix/logistics-wizard-webui/issues/107 --- src/modules/demos.js | 2 +- src/services/index.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/demos.js b/src/modules/demos.js index 7f8207b..2ac307f 100644 --- a/src/modules/demos.js +++ b/src/modules/demos.js @@ -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); diff --git a/src/services/index.js b/src/services/index.js index cd867cc..b6f3012 100644 --- a/src/services/index.js +++ b/src/services/index.js @@ -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}`); @@ -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', });