open-nomad/ui/app/adapters/node-pool.js
hc-github-team-nomad-core 63316363c9
Backport of ui: handle node pool requests to older regions into release/1.6.x (#18024)
This pull request was automerged via backport-assistant
2023-07-21 08:17:08 -05:00

35 lines
987 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationAdapter from './application';
import classic from 'ember-classic-decorator';
import { pluralize } from 'ember-inflector';
@classic
export default class NodePoolAdapter extends ApplicationAdapter {
urlForFindAll(modelName) {
let [relationshipResource, resource] = modelName.split('-');
resource = pluralize(resource);
return `/v1/${relationshipResource}/${resource}`;
}
findAll() {
return super.findAll(...arguments).catch((error) => {
// Handle the case where the node pool request is sent to a region that
// doesn't have node pools and the request is handled by the nodes
// endpoint.
const isNodeRequest = error.message.includes(
'node lookup failed: index error: UUID must be 36 characters'
);
if (isNodeRequest) {
return [];
}
// Rethrow to be handled downstream.
throw error;
});
}
}