diff --git a/ui/app/adapters/application.js b/ui/app/adapters/application.js index b1504ff03..a00c5cd05 100644 --- a/ui/app/adapters/application.js +++ b/ui/app/adapters/application.js @@ -3,6 +3,7 @@ import { computed, get } from '@ember/object'; import RESTAdapter from 'ember-data/adapters/rest'; import codesForError from '../utils/codes-for-error'; import removeRecord from '../utils/remove-record'; +import { default as NoLeaderError, NO_LEADER } from '../utils/no-leader-error'; export const namespace = 'v1'; @@ -21,6 +22,13 @@ export default RESTAdapter.extend({ } }), + handleResponse(status, headers, payload) { + if (status === 500 && payload === NO_LEADER) { + return new NoLeaderError(); + } + return this._super(...arguments); + }, + findAll() { return this._super(...arguments).catch(error => { const errorCodes = codesForError(error); diff --git a/ui/app/controllers/application.js b/ui/app/controllers/application.js index 15902ebd8..da3cdcfff 100644 --- a/ui/app/controllers/application.js +++ b/ui/app/controllers/application.js @@ -4,6 +4,7 @@ import { run } from '@ember/runloop'; import { observer, computed } from '@ember/object'; import Ember from 'ember'; import codesForError from '../utils/codes-for-error'; +import NoLeaderError from '../utils/no-leader-error'; export default Controller.extend({ config: service(), @@ -37,6 +38,11 @@ export default Controller.extend({ return this.get('errorCodes').includes('500'); }), + isNoLeader: computed('error', function() { + const error = this.get('error'); + return error instanceof NoLeaderError; + }), + throwError: observer('error', function() { if (this.get('config.isDev')) { run.next(() => { diff --git a/ui/app/templates/application.hbs b/ui/app/templates/application.hbs index 8d1a11672..a12a00c5f 100644 --- a/ui/app/templates/application.hbs +++ b/ui/app/templates/application.hbs @@ -4,7 +4,12 @@ {{else}}
- {{#if is500}} + {{#if isNoLeader}} +

No Cluster Leader

+

+ The cluster has no leader. Read about Outage Recovery. +

+ {{else if is500}}

Server Error

A server error prevented data from being sent to the client.

{{else if is404}} diff --git a/ui/app/utils/no-leader-error.js b/ui/app/utils/no-leader-error.js new file mode 100644 index 000000000..cf29a8119 --- /dev/null +++ b/ui/app/utils/no-leader-error.js @@ -0,0 +1,7 @@ +import { AdapterError } from 'ember-data/adapters/errors'; + +export const NO_LEADER = 'No cluster leader'; + +export default AdapterError.extend({ + message: NO_LEADER, +}); diff --git a/ui/tests/acceptance/application-errors-test.js b/ui/tests/acceptance/application-errors-test.js index 4baa2816e..b07dbdd63 100644 --- a/ui/tests/acceptance/application-errors-test.js +++ b/ui/tests/acceptance/application-errors-test.js @@ -52,3 +52,18 @@ test('the 403 error page links to the ACL tokens page', function(assert) { ); }); }); + +test('the no leader error state gets its own error message', function(assert) { + server.pretender.get('/v1/jobs', () => [500, {}, 'No cluster leader']); + + JobsList.visit(); + + andThen(() => { + assert.ok(JobsList.error.isPresent, 'An error is shown'); + assert.equal( + JobsList.error.title, + 'No Cluster Leader', + 'The error is specifically for the lack of a cluster leader' + ); + }); +});