From aeb4ea8da95e9dba2d33fcc5753aa1e555a5b4ef Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Nov 02 2017 15:58:40 +0000 Subject: [PATCH 1/3] Make the AddWidgetDialog respect the widget's is_large attribute --- diff --git a/hubs/static/client/app/components/AddWidget/AddWidgetDialog.js b/hubs/static/client/app/components/AddWidget/AddWidgetDialog.js index 83247e2..2cf369b 100644 --- a/hubs/static/client/app/components/AddWidget/AddWidgetDialog.js +++ b/hubs/static/client/app/components/AddWidget/AddWidgetDialog.js @@ -181,7 +181,7 @@ class AddWidgetDialog extends React.Component { return ( From 2dd176fa5b320cf560f3fab772269499fc370dd0 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Nov 02 2017 15:59:04 +0000 Subject: [PATCH 2/3] Dispatch actions, don't just return them --- diff --git a/hubs/static/client/app/core/actions/hub.js b/hubs/static/client/app/core/actions/hub.js index 6099d2e..bdb6600 100644 --- a/hubs/static/client/app/core/actions/hub.js +++ b/hubs/static/client/app/core/actions/hub.js @@ -36,7 +36,7 @@ export function fetchHub() { hub => dispatch(receiveHub(hub)), error => { dispatch(addFlashMessage(error.message, "error")); - return hubRequestFailed(); + return dispatch(hubRequestFailed()); } ); } @@ -75,7 +75,7 @@ export function saveHub(config, users) { }, error => { dispatch(addFlashMessage(error.message, "error")); - return putHubFailure(error.message); + return dispatch(putHubFailure(error.message)); }) } } diff --git a/hubs/static/client/app/core/actions/widget.js b/hubs/static/client/app/core/actions/widget.js index c9da158..5af6e96 100644 --- a/hubs/static/client/app/core/actions/widget.js +++ b/hubs/static/client/app/core/actions/widget.js @@ -49,7 +49,7 @@ function putConfigSucceeded(widgetId) { let url = state.entities.widgets.byId[widgetId].selfUrl; return apiCall(url).then( (widgetProps) => (dispatch(putConfigSuccess(widgetId, widgetProps))), - error => (putConfigFailure(widgetId, error.message)) + error => (dispatch(putConfigFailure(widgetId, error.message))) ); } } diff --git a/hubs/static/client/app/core/actions/widgets.js b/hubs/static/client/app/core/actions/widgets.js index 4a4abaf..925aaa0 100644 --- a/hubs/static/client/app/core/actions/widgets.js +++ b/hubs/static/client/app/core/actions/widgets.js @@ -38,7 +38,7 @@ export function fetchWidgets() { widgets => dispatch(receiveWidgets(widgets)), error => { dispatch(addFlashMessage(error.message, "error")); - return widgetsRequestFailed(); + return dispatch(widgetsRequestFailed()); } ); } @@ -87,7 +87,7 @@ export function getAvailableWidgets() { }, error => { dispatch(addFlashMessage(error.message, "error")); - return widgetsAvailFailure(error.message); + return dispatch(widgetsAvailFailure(error.message)); }) } } From 40820f3905397003f3e7c0d028678b4f16d4943a Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Nov 02 2017 15:59:42 +0000 Subject: [PATCH 3/3] Improve the backend error handling code --- diff --git a/hubs/static/client/app/core/utils.js b/hubs/static/client/app/core/utils.js index d3dd241..4499b04 100644 --- a/hubs/static/client/app/core/utils.js +++ b/hubs/static/client/app/core/utils.js @@ -12,29 +12,37 @@ export function backendCall(url, fetchConfig, json=false) { fetchConfig = Object.assign({}, baseFetchConfig, fetchConfig); return fetch(url, {...baseFetchConfig, ...fetchConfig}).then( (response) => { - if (response.ok) { - return json ? response.json() : response.text(); - } else { - return response.text().then((msg) => { - throw new Error(msg); + let resultPromise = json ? response.json() : response.text(); + if (!response.ok) { + resultPromise = resultPromise.then((content) => { + if (json) { + // It's an object describing the error. + throw content; + } else { + // It's already a text message. + throw new Error(content); + } }); } + return resultPromise; } - ).catch((error) => { - console.error(error.message); - throw error; - }); + ); } export function apiCall(url, fetchConfig) { - return backendCall(url, fetchConfig, true).then(result => { - if (result.status === "OK") { - return result.data; - } else { - throw new Error(result.message); + return backendCall(url, fetchConfig, true).then( + result => { + if (result.status === "OK") { + return result.data; + } else { + throw new Error(result.message); + } + }, + error => { + throw new Error(error.message); } - }); + ); }