commit 5d9d393f42bbba99c0f19a6e1486c3881f5eafe2 Author: Ole Date: Fri Oct 9 17:54:53 2020 +0200 Refactor reload 6: Merge try blocks This function is very hard to follow. Making small steps to ensure careful review. This reduces duplication of setting this._loading. Change-Id: I6f197cb7198a0e359c6ce062664a893c19f0d553 diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts index 093b1c3..b9c268d 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts +++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts @@ -353,18 +353,11 @@ export class GrDiffHost extends GestureEventListeners( this._coverageRanges = []; this._getCoverageData(); - let diff: DiffInfo; try { - diff = await this._getDiff(); + const diff = await this._getDiff(); this._loadedWhitespaceLevel = whitespaceLevel; this._reportDiff(diff); - } catch (e) { - this._handleGetDiffError(e); - this._loading = false; - return; - } - try { await this._loadDiffAssets(diff); // Not waiting for coverage ranges intentionally as @@ -397,8 +390,12 @@ export class GrDiffHost extends GestureEventListeners( this.reporting.diffViewContentDisplayed(); } await result; - } catch (err) { - console.warn('Error encountered loading diff:', err); + } catch (e) { + if (e instanceof Response) { + this._handleGetDiffError(e); + } else { + console.warn('Error encountered loading diff:', e); + } } this._loading = false; } diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.js b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.js index a7b7c6d..e4bfdfd 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.js @@ -468,9 +468,9 @@ suite('gr-diff-host tests', () => { test('reload resolves on error', () => { const onErrStub = sinon.stub(element, '_handleGetDiffError'); - const error = {ok: false, status: 500}; + const error = new Response(null, {ok: false, status: 500}); sinon.stub(element.$.restAPI, 'getDiff').callsFake( - (changeNum, basePatchNum, patchNum, path, onErr) => { + (changeNum, basePatchNum, patchNum, path, whitespace, onErr) => { onErr(error); }); element.patchRange = {};