Show trace ID when throwing page-errors
Change-Id: Ied1ebff1d279bf35840a6cbf0e0d950da7be2d2e
diff --git a/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts b/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
index 8f9dfe2..8352319 100644
--- a/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
+++ b/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
@@ -75,6 +75,37 @@
};
}
+export function constructServerErrorMsg({
+ errorText,
+ status,
+ statusText,
+ url,
+ trace,
+ tip,
+}: ErrorMsg) {
+ let err = '';
+ if (tip) {
+ err += `${tip}\n\n`;
+ }
+ err += `Error ${status}`;
+ if (statusText) {
+ err += ` (${statusText})`;
+ }
+ if (errorText || url) {
+ err += ': ';
+ }
+ if (errorText) {
+ err += errorText;
+ }
+ if (url) {
+ err += `\nEndpoint: ${url}`;
+ }
+ if (trace) {
+ err += `\nTrace Id: ${trace}`;
+ }
+ return err;
+}
+
@customElement('gr-error-manager')
export class GrErrorManager extends PolymerElement {
static get template() {
@@ -221,7 +252,7 @@
this._showQuotaExceeded({status, statusText});
} else {
this._showErrorDialog(
- this._constructServerErrorMsg({
+ constructServerErrorMsg({
status,
statusText,
errorText,
@@ -247,7 +278,7 @@
? 'You might have not enough privileges.'
: 'You might have not enough privileges. Sign in and try again.';
this._showErrorDialog(
- this._constructServerErrorMsg({
+ constructServerErrorMsg({
status,
statusText,
errorText,
@@ -266,7 +297,7 @@
const tip = 'Try again later';
const errorText = 'Too many requests from this client';
this._showErrorDialog(
- this._constructServerErrorMsg({
+ constructServerErrorMsg({
status,
statusText,
errorText,
@@ -275,37 +306,6 @@
);
}
- _constructServerErrorMsg({
- errorText,
- status,
- statusText,
- url,
- trace,
- tip,
- }: ErrorMsg) {
- let err = '';
- if (tip) {
- err += `${tip}\n\n`;
- }
- err += `Error ${status}`;
- if (statusText) {
- err += ` (${statusText})`;
- }
- if (errorText || url) {
- err += ': ';
- }
- if (errorText) {
- err += errorText;
- }
- if (url) {
- err += `\nEndpoint: ${url}`;
- }
- if (trace) {
- err += `\nTrace Id: ${trace}`;
- }
- return err;
- }
-
private readonly handleShowAlert = (e: CustomEvent<ShowAlertEventDetail>) => {
this._showAlert(
e.detail.message,
diff --git a/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager_test.js b/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager_test.js
index fe4d9da..4cf15b4 100644
--- a/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager_test.js
+++ b/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager_test.js
@@ -18,7 +18,7 @@
import '../../../test/common-test-setup-karma.js';
import './gr-error-manager.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
-import {__testOnly_ErrorType} from './gr-error-manager.js';
+import {constructServerErrorMsg, __testOnly_ErrorType} from './gr-error-manager.js';
import {stubRestApi} from '../../../test/test-utils.js';
import {appContext} from '../../../services/app-context.js';
import {createPreferences} from '../../../test/test-data-generators.js';
@@ -132,27 +132,26 @@
});
});
- test('_constructServerErrorMsg', () => {
+ test('constructServerErrorMsg', () => {
const errorText = 'change conflicts';
const status = 409;
const statusText = 'Conflict';
const url = '/my/test/url';
- assert.equal(element._constructServerErrorMsg({status}),
+ assert.equal(constructServerErrorMsg({status}),
'Error 409');
- assert.equal(element._constructServerErrorMsg({status, url}),
+ assert.equal(constructServerErrorMsg({status, url}),
'Error 409: \nEndpoint: /my/test/url');
- assert.equal(element.
- _constructServerErrorMsg({status, statusText, url}),
- 'Error 409 (Conflict): \nEndpoint: /my/test/url');
- assert.equal(element._constructServerErrorMsg({
+ assert.equal(constructServerErrorMsg({status, statusText, url}),
+ 'Error 409 (Conflict): \nEndpoint: /my/test/url');
+ assert.equal(constructServerErrorMsg({
status,
statusText,
errorText,
url,
}), 'Error 409 (Conflict): change conflicts' +
'\nEndpoint: /my/test/url');
- assert.equal(element._constructServerErrorMsg({
+ assert.equal(constructServerErrorMsg({
status,
statusText,
errorText,
diff --git a/polygerrit-ui/app/elements/gr-app-element.ts b/polygerrit-ui/app/elements/gr-app-element.ts
index be9c7c5..c9f0506 100644
--- a/polygerrit-ui/app/elements/gr-app-element.ts
+++ b/polygerrit-ui/app/elements/gr-app-element.ts
@@ -55,7 +55,10 @@
ElementPropertyDeepChange,
ServerInfo,
} from '../types/common';
-import {GrErrorManager} from './core/gr-error-manager/gr-error-manager';
+import {
+ constructServerErrorMsg,
+ GrErrorManager,
+} from './core/gr-error-manager/gr-error-manager';
import {GrOverlay} from './shared/gr-overlay/gr-overlay';
import {GrRegistrationDialog} from './settings/gr-registration-dialog/gr-registration-dialog';
import {
@@ -565,7 +568,15 @@
err.emoji = 'o_O';
if (response) {
response.text().then(text => {
- err.moreInfo = text;
+ const trace =
+ response.headers && response.headers.get('X-Gerrit-Trace');
+ const {status, statusText} = response;
+ err.moreInfo = constructServerErrorMsg({
+ status,
+ statusText,
+ errorText: text,
+ trace,
+ });
this._lastError = err;
});
}