Show error toast on plugin network errors
Change-Id: I6500d4f2518f338fde364c7a9c23c5d4daa7eac1
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user