Skip to content

Commit

Permalink
Specialized No Leader error page
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Jul 31, 2018
1 parent 6db90c7 commit 4b84d41
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ui/app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -20,6 +21,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);
Expand Down
6 changes: 6 additions & 0 deletions ui/app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -30,6 +31,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(() => {
Expand Down
7 changes: 6 additions & 1 deletion ui/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
{{else}}
<div class="error-container">
<div data-test-error class="error-message">
{{#if is500}}
{{#if isNoLeader}}
<h1 data-test-error-title class="title is-spaced">No Cluster Leader</h1>
<p data-test-error-message class="subtitle">
The cluster has no leader. <a href="https://www.nomadproject.io/guides/outage.html"> Read about Outage Recovery.</a>
</p>
{{else if is500}}
<h1 data-test-error-title class="title is-spaced">Server Error</h1>
<p data-test-error-message class="subtitle">A server error prevented data from being sent to the client.</p>
{{else if is404}}
Expand Down
11 changes: 11 additions & 0 deletions ui/app/utils/no-leader-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AdapterError } from 'ember-data/adapters/errors';

export const NO_LEADER = 'No cluster leader';

const NoLeaderError = function() {
AdapterError.call(this, [], NO_LEADER);
};

NoLeaderError.prototype = Object.create(AdapterError.prototype);

export default NoLeaderError;
15 changes: 15 additions & 0 deletions ui/tests/acceptance/application-errors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});

0 comments on commit 4b84d41

Please sign in to comment.