diff --git a/client/src/actions/index.js b/client/src/actions/index.js index 862c36cf..5c0341fc 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -428,26 +428,21 @@ export const testUpstreamSuccess = createAction('TEST_UPSTREAM_SUCCESS'); export const testUpstream = servers => async (dispatch) => { dispatch(testUpstreamRequest()); try { - if (servers.length > 0) { - const upstreamResponse = await apiClient.testUpstream(servers); + const upstreamResponse = await apiClient.testUpstream(servers); - const testMessages = Object.keys(upstreamResponse).map((key) => { - const message = upstreamResponse[key]; - if (message !== 'OK') { - dispatch(addErrorToast({ error: `Server "${key}": could not be used, please check that you've written it correctly` })); - } - return message; - }); - - if (testMessages.every(message => message === testMessages[0])) { - dispatch(addSuccessToast('All servers is OK')); + const testMessages = Object.keys(upstreamResponse).map((key) => { + const message = upstreamResponse[key]; + if (message !== 'OK') { + dispatch(addErrorToast({ error: `Server "${key}": could not be used, please check that you've written it correctly` })); } + return message; + }); - dispatch(testUpstreamSuccess()); - } else { - dispatch(addErrorToast({ error: 'No servers specified' })); - dispatch(testUpstreamFailure()); + if (testMessages.every(message => message === testMessages[0])) { + dispatch(addSuccessToast('All servers is OK')); } + + dispatch(testUpstreamSuccess()); } catch (error) { dispatch(addErrorToast({ error })); dispatch(testUpstreamFailure()); diff --git a/client/src/components/Settings/index.js b/client/src/components/Settings/index.js index ed3a9693..14140c4f 100644 --- a/client/src/components/Settings/index.js +++ b/client/src/components/Settings/index.js @@ -44,7 +44,11 @@ export default class Settings extends Component { }; handleUpstreamTest = () => { - this.props.testUpstream(this.props.settings.upstream); + if (this.props.settings.upstream.length > 0) { + this.props.testUpstream(this.props.settings.upstream); + } else { + this.props.addErrorToast({ error: 'No servers specified' }); + } }; renderSettings = (settings) => { diff --git a/client/src/containers/Settings.js b/client/src/containers/Settings.js index d53da73b..3a790799 100644 --- a/client/src/containers/Settings.js +++ b/client/src/containers/Settings.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import { initSettings, toggleSetting, handleUpstreamChange, setUpstream, testUpstream } from '../actions'; +import { initSettings, toggleSetting, handleUpstreamChange, setUpstream, testUpstream, addErrorToast } from '../actions'; import Settings from '../components/Settings'; const mapStateToProps = (state) => { @@ -14,6 +14,7 @@ const mapDispatchToProps = { handleUpstreamChange, setUpstream, testUpstream, + addErrorToast, }; export default connect(