Gracefully handle the 501 case

Enterprise endpoints return a 501 in the open source build. 5xx
errors throw by default, so handle this one since it's expected
for things such as namespaces.
This commit is contained in:
Michael Lange
2017-10-10 11:23:10 -07:00
parent 5f23b8411a
commit 45b8cb067e
6 changed files with 36 additions and 7 deletions

View File

@@ -19,6 +19,18 @@ export default RESTAdapter.extend({
);
}),
findAll() {
return this._super(...arguments).catch(error => {
if (error.code === '501' || (error.errors && error.errors.findBy('status', '501'))) {
// Feature is not implemented in this version of Nomad
return [];
}
// Rethrow to be handled downstream
throw error;
});
},
// Single record requests deviate from REST practice by using
// the singular form of the resource name.
//

View File

@@ -19,9 +19,9 @@
<div class="boxed-section job-stats">
<div class="boxed-section-body">
<span><strong>Type:</strong> {{model.type}} | </span>
<span><strong>Priority:</strong> {{model.priority}} | </span>
<span><strong>Priority:</strong> {{model.priority}} </span>
{{#if model.namespace}}
<span><strong>Namespace:</strong> {{model.namespace.name}}</span>
<span> | <strong>Namespace:</strong> {{model.namespace.name}}</span>
{{/if}}
</div>
</div>

View File

@@ -1,4 +1,5 @@
import Ember from 'ember';
import Response from 'ember-cli-mirage/response';
import { HOSTS } from './common';
const { copy } = Ember;
@@ -60,8 +61,23 @@ export default function() {
this.get('/allocation/:id');
this.get('/namespaces');
this.get('/namespace/:id');
this.get('/namespaces', function({ namespaces }) {
const records = namespaces.all();
if (records.length) {
return this.serialize(records);
}
return new Response(501, {}, null);
});
this.get('/namespace/:id', function({ namespaces }, { params }) {
if (namespaces.all().length) {
return this.serialize(namespaces.find(params.id));
}
return new Response(501, {}, null);
});
this.get('/agent/members', function({ agents }) {
return {

View File

@@ -50,7 +50,7 @@ export default Factory.extend({
job.update({
taskGroupIds: groups.mapBy('id'),
task_group_ids: groups.mapBy('id'),
namespaceId: server.db.namespaces.length && pickOne(server.db.namespaces).id,
namespaceId: server.db.namespaces.length ? pickOne(server.db.namespaces).id : null,
});
const jobSummary = server.create('job-summary', {

View File

@@ -1,10 +1,12 @@
import { Factory, faker } from 'ember-cli-mirage';
export default Factory.extend({
id: i => `namespace-${i}`,
id: i => (i === 0 ? 'default' : `namespace-${i}`),
name() {
return this.id;
},
hash: () => faker.random.uuid(),
description: '',
});

View File

@@ -2,7 +2,6 @@ export default function(server) {
server.createList('agent', 3);
server.createList('node', 50);
server.create('namespace', { id: 'default' });
server.createList('namespace', 3);
server.createList('job', 15);