From ae6658dd941c4a32a0af8a6cb830c19dc822f4f2 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 28 Sep 2017 10:47:02 -0700 Subject: [PATCH] Handle 404s for agents --- ui/app/routes/servers/server.js | 10 ++++++++++ ui/app/serializers/agent.js | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 ui/app/routes/servers/server.js diff --git a/ui/app/routes/servers/server.js b/ui/app/routes/servers/server.js new file mode 100644 index 000000000..c4c67569f --- /dev/null +++ b/ui/app/routes/servers/server.js @@ -0,0 +1,10 @@ +import Ember from 'ember'; +import notifyError from 'nomad-ui/utils/notify-error'; + +const { Route } = Ember; + +export default Route.extend({ + model() { + return this._super(...arguments).catch(notifyError(this)); + }, +}); diff --git a/ui/app/serializers/agent.js b/ui/app/serializers/agent.js index e3cb04997..f54db7276 100644 --- a/ui/app/serializers/agent.js +++ b/ui/app/serializers/agent.js @@ -1,4 +1,5 @@ import ApplicationSerializer from './application'; +import { AdapterError } from 'ember-data/adapters/errors'; export default ApplicationSerializer.extend({ attrs: { @@ -8,6 +9,16 @@ export default ApplicationSerializer.extend({ }, normalize(typeHash, hash) { + if (!hash) { + // It's unusual to throw an adapter error from a serializer, + // but there is no single server end point so the serializer + // acts like the API in this case. + const error = new AdapterError([{ status: '404' }]); + + error.message = 'Requested Agent was not found in set of available Agents'; + throw error; + } + hash.ID = hash.Name; hash.Datacenter = hash.Tags && hash.Tags.dc; hash.Region = hash.Tags && hash.Tags.region;