Utilize gr-error-dialog
Use an error dialog for change action failures and server errors. Bug: Issue 8457 Change-Id: I021065ebfd286ed9a8ae8402799a6e4173065a28
This commit is contained in:
@@ -212,6 +212,12 @@
|
||||
* @event show-alert
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fires when a change action fails.
|
||||
*
|
||||
* @event show-error
|
||||
*/
|
||||
|
||||
properties: {
|
||||
/**
|
||||
* @type {{
|
||||
@@ -1154,7 +1160,7 @@
|
||||
|
||||
_handleResponseError(response) {
|
||||
return response.text().then(errText => {
|
||||
this.fire('show-alert',
|
||||
this.fire('show-error',
|
||||
{message: `Could not perform action: ${errText}`});
|
||||
if (!errText.startsWith('Change is already up to date')) {
|
||||
throw Error(errText);
|
||||
|
@@ -1370,6 +1370,7 @@ limitations under the License.
|
||||
suite('_send', () => {
|
||||
let cleanup;
|
||||
let payload;
|
||||
let onShowError;
|
||||
let onShowAlert;
|
||||
|
||||
setup(() => {
|
||||
@@ -1378,6 +1379,8 @@ limitations under the License.
|
||||
element.latestPatchNum = 12;
|
||||
payload = {foo: 'bar'};
|
||||
|
||||
onShowError = sinon.stub();
|
||||
element.addEventListener('show-error', onShowError);
|
||||
onShowAlert = sinon.stub();
|
||||
element.addEventListener('show-alert', onShowAlert);
|
||||
});
|
||||
@@ -1395,7 +1398,7 @@ limitations under the License.
|
||||
test('change action', () => {
|
||||
return element._send('DELETE', payload, '/endpoint', false, cleanup)
|
||||
.then(() => {
|
||||
assert.isFalse(onShowAlert.called);
|
||||
assert.isFalse(onShowError.called);
|
||||
assert.isTrue(cleanup.calledOnce);
|
||||
assert.isTrue(sendStub.calledWith(42, 'DELETE', '/endpoint',
|
||||
null, payload));
|
||||
@@ -1405,7 +1408,7 @@ limitations under the License.
|
||||
test('revision action', () => {
|
||||
return element._send('DELETE', payload, '/endpoint', true, cleanup)
|
||||
.then(() => {
|
||||
assert.isFalse(onShowAlert.called);
|
||||
assert.isFalse(onShowError.called);
|
||||
assert.isTrue(cleanup.calledOnce);
|
||||
assert.isTrue(sendStub.calledWith(42, 'DELETE', '/endpoint',
|
||||
12, payload));
|
||||
@@ -1423,6 +1426,7 @@ limitations under the License.
|
||||
return element._send('DELETE', payload, '/endpoint', true, cleanup)
|
||||
.then(() => {
|
||||
assert.isTrue(onShowAlert.calledOnce);
|
||||
assert.isFalse(onShowError.called);
|
||||
assert.isTrue(cleanup.calledOnce);
|
||||
assert.isFalse(sendStub.called);
|
||||
});
|
||||
@@ -1441,7 +1445,7 @@ limitations under the License.
|
||||
|
||||
return element._send('DELETE', payload, '/endpoint', true, cleanup)
|
||||
.then(() => {
|
||||
assert.isFalse(onShowAlert.called);
|
||||
assert.isFalse(onShowError.called);
|
||||
assert.isTrue(cleanup.called);
|
||||
assert.isTrue(sendStub.calledOnce);
|
||||
assert.isTrue(handleErrorStub.called);
|
||||
|
@@ -17,11 +17,20 @@ limitations under the License.
|
||||
|
||||
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../core/gr-error-dialog/gr-error-dialog.html">
|
||||
<link rel="import" href="../../shared/gr-alert/gr-alert.html">
|
||||
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
|
||||
<dom-module id="gr-error-manager">
|
||||
<template>
|
||||
<gr-overlay with-backdrop id="errorOverlay">
|
||||
<gr-error-dialog
|
||||
id="errorDialog"
|
||||
on-dismiss="_handleDismissErrorDialog"
|
||||
confirm-label="Dismiss"
|
||||
confirm-on-enter></gr-error-dialog>
|
||||
</gr-overlay>
|
||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||
</template>
|
||||
<script src="gr-error-manager.js"></script>
|
||||
|
@@ -62,6 +62,7 @@
|
||||
this.listen(document, 'network-error', '_handleNetworkError');
|
||||
this.listen(document, 'auth-error', '_handleAuthError');
|
||||
this.listen(document, 'show-alert', '_handleShowAlert');
|
||||
this.listen(document, 'show-error', '_handleShowErrorDialog');
|
||||
this.listen(document, 'visibilitychange', '_handleVisibilityChange');
|
||||
this.listen(document, 'show-auth-required', '_handleAuthRequired');
|
||||
},
|
||||
@@ -73,6 +74,7 @@
|
||||
this.unlisten(document, 'auth-error', '_handleAuthError');
|
||||
this.unlisten(document, 'show-auth-required', '_handleAuthRequired');
|
||||
this.unlisten(document, 'visibilitychange', '_handleVisibilityChange');
|
||||
this.unlisten(document, 'show-error', '_handleShowErrorDialog');
|
||||
},
|
||||
|
||||
_shouldSuppressError(msg) {
|
||||
@@ -101,7 +103,7 @@
|
||||
// This indicates the auth token is no longer valid.
|
||||
this._handleAuthError();
|
||||
} else if (!this._shouldSuppressError(text)) {
|
||||
this._showAlert('Server error: ' + text);
|
||||
this._showErrorDialog('Server error: ' + text);
|
||||
}
|
||||
console.error(text);
|
||||
});
|
||||
@@ -257,5 +259,18 @@
|
||||
_handleWindowFocus() {
|
||||
this.flushDebouncer('checkLoggedIn');
|
||||
},
|
||||
|
||||
_handleShowErrorDialog(e) {
|
||||
this._showErrorDialog(e.detail.message);
|
||||
},
|
||||
|
||||
_handleDismissErrorDialog() {
|
||||
this.$.errorOverlay.close();
|
||||
},
|
||||
|
||||
_showErrorDialog(message) {
|
||||
this.$.errorDialog.text = message;
|
||||
this.$.errorOverlay.open();
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
@@ -87,7 +87,7 @@ limitations under the License.
|
||||
});
|
||||
|
||||
test('show normal server error', done => {
|
||||
const showAlertStub = sandbox.stub(element, '_showAlert');
|
||||
const showErrorStub = sandbox.stub(element, '_showErrorDialog');
|
||||
const textSpy = sandbox.spy(() => { return Promise.resolve('ZOMG'); });
|
||||
element.fire('server-error', {response: {status: 500, text: textSpy}});
|
||||
|
||||
@@ -96,8 +96,8 @@ limitations under the License.
|
||||
element.$.restAPI.getLoggedIn.lastCall.returnValue,
|
||||
textSpy.lastCall.returnValue,
|
||||
]).then(() => {
|
||||
assert.isTrue(showAlertStub.calledOnce);
|
||||
assert.isTrue(showAlertStub.lastCall.calledWithExactly(
|
||||
assert.isTrue(showErrorStub.calledOnce);
|
||||
assert.isTrue(showErrorStub.lastCall.calledWithExactly(
|
||||
'Server error: ZOMG'));
|
||||
done();
|
||||
});
|
||||
@@ -279,5 +279,21 @@ limitations under the License.
|
||||
element._showAlert();
|
||||
assert.isTrue(hideStub.calledOnce);
|
||||
});
|
||||
|
||||
test('show-error', () => {
|
||||
const openStub = sandbox.stub(element.$.errorOverlay, 'open');
|
||||
const closeStub = sandbox.stub(element.$.errorOverlay, 'close');
|
||||
const message = 'test message';
|
||||
element.fire('show-error', {message});
|
||||
flushAsynchronousOperations();
|
||||
|
||||
assert.isTrue(openStub.called);
|
||||
assert.equal(element.$.errorDialog.text, message);
|
||||
|
||||
element.$.errorDialog.fire('dismiss');
|
||||
flushAsynchronousOperations();
|
||||
|
||||
assert.isTrue(closeStub.called);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user