Show error toast on plugin network errors

Change-Id: I6500d4f2518f338fde364c7a9c23c5d4daa7eac1
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context.js
index 84b7f0a..5ac8773 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context.js
@@ -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;
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context_test.html
index 7c18a99..bf6a046 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-action-context_test.html
@@ -128,5 +128,26 @@
       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>