Add alert on failed requests

This commit is contained in:
Ildar Kamalov 2018-09-12 12:58:55 +03:00
parent e2cf9ffd84
commit 6c70d8ca37
5 changed files with 33 additions and 4 deletions

View File

@ -324,6 +324,11 @@
"resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.2.0.tgz", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.2.0.tgz",
"integrity": "sha1-6GuBnGAs+IIa1jdBNpjx3sAhhHo=" "integrity": "sha1-6GuBnGAs+IIa1jdBNpjx3sAhhHo="
}, },
"alertifyjs": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/alertifyjs/-/alertifyjs-1.11.1.tgz",
"integrity": "sha512-8rw5zvMlg0Idltq15OOU9tGabYVA/I8JTNIM5ICUXqvrdPb7cfl+sSkTv9pDc6bbB8p9L85GtmOG7SUSv+bugQ=="
},
"align-text": { "align-text": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz",

View File

@ -10,6 +10,7 @@
}, },
"dependencies": { "dependencies": {
"@nivo/line": "^0.42.1", "@nivo/line": "^0.42.1",
"alertifyjs": "^1.11.1",
"axios": "^0.18.0", "axios": "^0.18.0",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"date-fns": "^1.29.0", "date-fns": "^1.29.0",

View File

@ -1,5 +1,6 @@
import { createAction } from 'redux-actions'; import { createAction } from 'redux-actions';
import round from 'lodash/round'; import round from 'lodash/round';
import alertify from 'alertifyjs';
import { normalizeHistory, normalizeFilteringStatus, normalizeLogs } from '../helpers/helpers'; import { normalizeHistory, normalizeFilteringStatus, normalizeLogs } from '../helpers/helpers';
import Api from '../api/Api'; import Api from '../api/Api';
@ -119,6 +120,7 @@ export const disableDns = () => async (dispatch) => {
dispatch(disableDnsSuccess()); dispatch(disableDnsSuccess());
} catch (error) { } catch (error) {
console.error(error); console.error(error);
alertify.error(`Failed to disable DNS with status code ${error.response.status}`);
dispatch(disableDnsFailure()); dispatch(disableDnsFailure());
} }
}; };
@ -154,8 +156,13 @@ export const getTopStats = () => async (dispatch, getState) => {
const state = getState(); const state = getState();
const timer = setInterval(async () => { const timer = setInterval(async () => {
if (state.dashboard.isCoreRunning) { if (state.dashboard.isCoreRunning) {
try {
const stats = await apiClient.getGlobalStatsTop(); const stats = await apiClient.getGlobalStatsTop();
dispatch(getTopStatsSuccess(stats)); dispatch(getTopStatsSuccess(stats));
} catch (error) {
alertify.error(`Failed to load statistics with status code ${error.response.status}`);
dispatch(getTopStatsFailure());
}
clearInterval(timer); clearInterval(timer);
} }
}, 100); }, 100);
@ -175,8 +182,13 @@ export const getLogs = () => async (dispatch, getState) => {
const state = getState(); const state = getState();
const timer = setInterval(async () => { const timer = setInterval(async () => {
if (state.dashboard.isCoreRunning) { if (state.dashboard.isCoreRunning) {
try {
const logs = normalizeLogs(await apiClient.getQueryLog()); const logs = normalizeLogs(await apiClient.getQueryLog());
dispatch(getLogsSuccess(logs)); dispatch(getLogsSuccess(logs));
} catch (error) {
alertify.error(`Failed to load query log with status code ${error.response.status}`);
dispatch(getLogsFailure());
}
clearInterval(timer); clearInterval(timer);
} }
}, 100); }, 100);

View File

@ -3,8 +3,10 @@ import { HashRouter, Route } from 'react-router-dom';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import 'react-table/react-table.css'; import 'react-table/react-table.css';
import 'alertifyjs/build/css/alertify.min.css';
import '../ui/Tabler.css'; import '../ui/Tabler.css';
import '../ui/ReactTable.css'; import '../ui/ReactTable.css';
import '../ui/Alertify.css';
import './index.css'; import './index.css';
import Header from '../../containers/Header'; import Header from '../../containers/Header';

View File

@ -0,0 +1,9 @@
.alertify-notifier .ajs-message {
width: 280px;
font-weight: 600;
color: #fff;
}
.alertify-notifier .ajs-message.ajs-error {
background-color: rgba(236, 53, 53, 0.76);
}