Show error toast on plugin network errors

Change-Id: I6500d4f2518f338fde364c7a9c23c5d4daa7eac1
This commit is contained in:
Viktar Donich
2018-05-16 13:52:10 -07:00
parent 31c377f420
commit cd9f2183b0
2 changed files with 29 additions and 1 deletions

View File

@@ -93,7 +93,14 @@
}
this.plugin.restApi()
.send(this.action.method, this.action.__url, payload)
.then(onSuccess);
.then(onSuccess)
.catch(error => {
document.dispatchEvent(new CustomEvent('show-alert', {
detail: {
message: `Plugin network error: ${error}`,
},
}));
});
};
window.GrPluginActionContext = GrPluginActionContext;

View File

@@ -128,5 +128,26 @@ limitations under the License.
assert.isTrue(sendStub.calledWith(
'METHOD', '/changes/1/revisions/2/foo~bar', payload));
});
test('call error', done => {
instance.action = {
method: 'METHOD',
__key: 'key',
__url: '/changes/1/revisions/2/foo~bar',
};
const sendStub = sandbox.stub().returns(Promise.reject('boom'));
sandbox.stub(plugin, 'restApi').returns({
send: sendStub,
});
const errorStub = sandbox.stub();
document.addEventListener('network-error', errorStub);
instance.call();
flush(() => {
assert.isTrue(errorStub.calledOnce);
assert.equal(errorStub.args[0][0].detail.message,
'Plugin network error: boom');
done();
});
});
});
</script>