Fix _handleSavingIncludedGroups crashes when a network error happens
In case of network errors, the error handler in the _handleSavingIncludedGroups method receives null as a first argument and an instance of Error object as a second argument. Change-Id: Iea242fa337abc02aefa3b2e7925f33685494ec8a
This commit is contained in:
@@ -230,16 +230,19 @@ class GrGroupMembers extends mixinBehaviors( [
|
||||
|
||||
_handleSavingIncludedGroups() {
|
||||
return this.$.restAPI.saveIncludedGroup(this._groupName,
|
||||
this._includedGroupSearchId.replace(/\+/g, ' '), err => {
|
||||
if (err.status === 404) {
|
||||
this.dispatchEvent(new CustomEvent('show-alert', {
|
||||
detail: {message: SAVING_ERROR_TEXT},
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
}));
|
||||
return err;
|
||||
this._includedGroupSearchId.replace(/\+/g, ' '), (errResponse, err) => {
|
||||
if (errResponse) {
|
||||
if (errResponse.status === 404) {
|
||||
this.dispatchEvent(new CustomEvent('show-alert', {
|
||||
detail: {message: SAVING_ERROR_TEXT},
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
}));
|
||||
return errResponse;
|
||||
}
|
||||
throw Error(err.statusText);
|
||||
}
|
||||
throw Error(err.statusText);
|
||||
throw err;
|
||||
})
|
||||
.then(config => {
|
||||
if (!config) {
|
||||
|
||||
@@ -213,10 +213,12 @@ suite('gr-group-members tests', () => {
|
||||
const memberName = 'bad-name';
|
||||
const alertStub = sinon.stub();
|
||||
element.addEventListener('show-alert', alertStub);
|
||||
const error = new Error('error');
|
||||
error.status = 404;
|
||||
sinon.stub(element.$.restAPI, 'saveGroupMembers').callsFake(
|
||||
() => Promise.reject(error));
|
||||
const errorResponse = {
|
||||
status: 404,
|
||||
ok: false,
|
||||
};
|
||||
sinon.stub(element.$.restAPI._restApiHelper, 'fetch').callsFake(
|
||||
() => Promise.resolve(errorResponse));
|
||||
|
||||
element.$.groupMemberSearchInput.text = memberName;
|
||||
element.$.groupMemberSearchInput.value = 1234;
|
||||
@@ -226,6 +228,28 @@ suite('gr-group-members tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('add included group network-error throws an exception', async () => {
|
||||
element._groupOwner = true;
|
||||
|
||||
const memberName = 'bad-name';
|
||||
const alertStub = sinon.stub();
|
||||
element.addEventListener('show-alert', alertStub);
|
||||
const err = new Error();
|
||||
sinon.stub(element.$.restAPI._restApiHelper, 'fetch').callsFake(
|
||||
() => Promise.reject(err));
|
||||
|
||||
element.$.groupMemberSearchInput.text = memberName;
|
||||
element.$.groupMemberSearchInput.value = 1234;
|
||||
|
||||
let exceptionThrown = false;
|
||||
try {
|
||||
await element._handleSavingIncludedGroups();
|
||||
} catch (e) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
assert.isTrue(exceptionThrown);
|
||||
});
|
||||
|
||||
test('_getAccountSuggestions empty', done => {
|
||||
element
|
||||
._getAccountSuggestions('nonexistent').then(accounts => {
|
||||
|
||||
Reference in New Issue
Block a user