From 8361079a857c0d21df295b3a13ac949e1d074445 Mon Sep 17 00:00:00 2001 From: djenriquez Date: Thu, 2 Mar 2017 21:10:29 -0800 Subject: [PATCH 1/3] Add exception for status sys/health 429 resp Status 429 is a valid response for the `sys/health` call from standby nodes --- src/vaultapi.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/vaultapi.js b/src/vaultapi.js index 435ed9a..5ae71bc 100644 --- a/src/vaultapi.js +++ b/src/vaultapi.js @@ -18,14 +18,17 @@ exports.callMethod = function (req, res) { headers: req.headers, data: req.body } - //console.log(config); axios.request(config) .then(function (resp) { res.json(resp.data); }) .catch(function (err) { - //console.error(err.response.data); - //console.error(err.stack); - res.status(err.response.status).send(err.response.data); + // Response code 429 is a valid status code returned by vault from stand-by nodes for the sys/health call + // https://www.vaultproject.io/docs/http/#429 + if (config.url === '/v1/sys/health' && err.response.status == 429) { + res.json(err.response.data); + } else { + res.status(err.response.status).send(err.response.data); + } }); }; \ No newline at end of file From 1c44b128766b2a97a46cae9e1ebe63e67ccea153 Mon Sep 17 00:00:00 2001 From: djenriquez Date: Thu, 2 Mar 2017 21:41:08 -0800 Subject: [PATCH 2/3] Applying a more elegant solution - Removing the logic from the backend and applying to the UI component directly --- app/components/shared/Header/Header.jsx | 9 +++++++++ src/health.js | 13 ------------- src/vaultapi.js | 9 ++------- 3 files changed, 11 insertions(+), 20 deletions(-) delete mode 100644 src/health.js diff --git a/app/components/shared/Header/Header.jsx b/app/components/shared/Header/Header.jsx index 045f2eb..3facabd 100644 --- a/app/components/shared/Header/Header.jsx +++ b/app/components/shared/Header/Header.jsx @@ -33,6 +33,15 @@ class Header extends React.Component { this.setState({ version: resp.data.version, }); + }) + .catch((error) => { + if (error.response.status === 429) { + this.setState({ + version: error.response.data.version, + }); + } else { + throw error; + } }); } diff --git a/src/health.js b/src/health.js deleted file mode 100644 index 50cf4be..0000000 --- a/src/health.js +++ /dev/null @@ -1,13 +0,0 @@ -exports.getHealth = function (req, resp) { - let endpoint = `/v1/sys/health`; - let vaultAddr = decodeURI(req.query['vaultaddr']); - let config = { headers: { 'X-Vault-Token': req.query['token'] } } - - axios.get(`${vaultAddr}${endpoint}`, config) - .then((resp) => { - res.json(resp.data.data); - }) - .catch((err) => { - console.error(err.stack); - }); -} \ No newline at end of file diff --git a/src/vaultapi.js b/src/vaultapi.js index 5ae71bc..e4337ef 100644 --- a/src/vaultapi.js +++ b/src/vaultapi.js @@ -18,17 +18,12 @@ exports.callMethod = function (req, res) { headers: req.headers, data: req.body } + axios.request(config) .then(function (resp) { res.json(resp.data); }) .catch(function (err) { - // Response code 429 is a valid status code returned by vault from stand-by nodes for the sys/health call - // https://www.vaultproject.io/docs/http/#429 - if (config.url === '/v1/sys/health' && err.response.status == 429) { - res.json(err.response.data); - } else { - res.status(err.response.status).send(err.response.data); - } + res.status(err.response.status).send(err.response.data); }); }; \ No newline at end of file From 395b75fc67fcafa4232ee354cd68e6a4ff10ff55 Mon Sep 17 00:00:00 2001 From: djenriquez Date: Thu, 2 Mar 2017 21:47:16 -0800 Subject: [PATCH 3/3] Using snackbar for error reporting --- app/components/shared/Header/Header.jsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/components/shared/Header/Header.jsx b/app/components/shared/Header/Header.jsx index 3facabd..0a068f0 100644 --- a/app/components/shared/Header/Header.jsx +++ b/app/components/shared/Header/Header.jsx @@ -7,13 +7,20 @@ import FontIcon from 'material-ui/FontIcon'; import { browserHistory } from 'react-router'; import CountDown from './countdown.js' import styles from './header.css'; -import { callVaultApi } from '../../shared/VaultUtils.jsx' +import { callVaultApi } from '../../shared/VaultUtils.jsx'; +import Snackbar from 'material-ui/Snackbar'; + var logout = () => { window.localStorage.removeItem('vaultAccessToken'); browserHistory.push('/login'); } +function snackBarMessage(message) { + let ev = new CustomEvent("snackbar", { detail: { message: message } }); + document.dispatchEvent(ev); +} + class Header extends React.Component { constructor(props) { super(props); @@ -40,7 +47,7 @@ class Header extends React.Component { version: error.response.data.version, }); } else { - throw error; + snackBarMessage(error); } }); }