Fixed error handling

This commit is contained in:
Luke "Jared" Bennett 2017-04-06 13:42:18 +01:00
parent 98f59fc20f
commit 66d03aae98
No known key found for this signature in database
GPG Key ID: 402ED51FB5D306C2
5 changed files with 23 additions and 15 deletions

View File

@ -1,9 +1,5 @@
/* eslint-disable */
function droplabAjaxException(message) {
this.message = message;
}
const Ajax = {
_loadUrlData: function _loadUrlData(url) {
var self = this;
@ -58,9 +54,7 @@ const Ajax = {
this._loadUrlData(config.endpoint)
.then(function(d) {
self._loadData(d, config, self);
}, config.onError).catch(function(e) {
throw new droplabAjaxException(e.message || e);
});
}, config.onError).catch(config.onError);
}
},
destroy: function() {

View File

@ -68,7 +68,7 @@ const AjaxFilter = {
this._loadUrlData(url)
.then(function(data) {
self._loadData(data, config, self);
}, config.onError);
}, config.onError).catch(config.onError);
}
},

View File

@ -1,3 +1,5 @@
/* global Flash */
import Ajax from '~/droplab/plugins/ajax';
import Filter from '~/droplab/plugins/filter';
@ -13,6 +15,11 @@ require('./filtered_search_dropdown');
endpoint,
method: 'setData',
loadingTemplate: this.loadingTemplate,
onError() {
/* eslint-disable no-new */
new Flash('An error occured fetching the dropdown data.');
/* eslint-enable no-new */
},
},
Filter: {
filterFunction: gl.DropdownUtils.filterWithSymbol.bind(null, this.symbol, input),

View File

@ -1,3 +1,5 @@
/* global Flash */
import AjaxFilter from '~/droplab/plugins/ajax_filter';
require('./filtered_search_dropdown');
@ -18,6 +20,11 @@ require('./filtered_search_dropdown');
},
searchValueFunction: this.getSearchInput.bind(this),
loadingTemplate: this.loadingTemplate,
onError() {
/* eslint-disable no-new */
new Flash('An error occured fetching the dropdown data.');
/* eslint-enable no-new */
},
},
};
}

View File

@ -65,7 +65,7 @@ describe 'Dropdown milestone', :feature, :js do
it 'should load all the milestones when opened' do
filtered_search.set('milestone:')
expect(dropdown_milestone_size).to be > 0
expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: 6)
end
end
@ -84,37 +84,37 @@ describe 'Dropdown milestone', :feature, :js do
it 'filters by name' do
filtered_search.send_keys('v1')
expect(dropdown_milestone_size).to eq(1)
expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: 1)
end
it 'filters by case insensitive name' do
filtered_search.send_keys('V1')
expect(dropdown_milestone_size).to eq(1)
expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: 1)
end
it 'filters by name with symbol' do
filtered_search.send_keys('%v1')
expect(dropdown_milestone_size).to eq(1)
expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: 1)
end
it 'filters by case insensitive name with symbol' do
filtered_search.send_keys('%V1')
expect(dropdown_milestone_size).to eq(1)
expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: 1)
end
it 'filters by special characters' do
filtered_search.send_keys('(+')
expect(dropdown_milestone_size).to eq(1)
expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: 1)
end
it 'filters by special characters with symbol' do
filtered_search.send_keys('%(+')
expect(dropdown_milestone_size).to eq(1)
expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: 1)
end
end