refactor(striker-ui-api): relocate getLocalHostUUID try-catch

main
Tsu-ba-me 2 years ago
parent be1332b4f3
commit 6afa296858
  1. 19
      striker-ui-api/src/lib/accessModule.ts
  2. 8
      striker-ui-api/src/lib/request_handlers/host/getHost.ts
  3. 8
      striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts
  4. 12
      striker-ui-api/src/lib/request_handlers/network-interface/getNetworkInterface.ts
  5. 2
      striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts

@ -139,10 +139,21 @@ const getAnvilData = (
spawnSyncOptions,
).stdout;
const getLocalHostUUID = () =>
execModuleSubroutine('host_uuid', {
subModuleName: 'Get',
}).stdout;
const getLocalHostUUID = () => {
let result;
try {
result = execModuleSubroutine('host_uuid', {
subModuleName: 'Get',
}).stdout;
} catch (subError) {
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`);
}
shout(`localHostUUID=[${result}]`);
return result;
};
export {
dbInsertOrUpdateJob as job,

@ -6,13 +6,7 @@ import { sanitizeQS } from '../../sanitizeQS';
export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
const { hostUUIDs } = request.query;
let localHostUUID: string;
try {
localHostUUID = getLocalHostUUID();
} catch (subError) {
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`);
}
const localHostUUID: string = getLocalHostUUID();
let query = `
SELECT

@ -39,7 +39,6 @@ export const getHostConnection = buildGetRequestHandler(
(request, buildQueryOptions) => {
const { hostUUIDs: rawHostUUIDs } = request.query;
let localHostUUID: string;
let rawDatabaseData: {
[hostUUID: string]: {
host: string;
@ -51,13 +50,8 @@ export const getHostConnection = buildGetRequestHandler(
};
};
try {
localHostUUID = getLocalHostUUID();
} catch (subError) {
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`);
}
const hostUUIDField = 'ip_add.ip_address_host_uuid';
const localHostUUID: string = getLocalHostUUID();
const { after: condHostUUIDs, before: beforeBuildIDCond } =
buildUnknownIDCondition(rawHostUUIDs, hostUUIDField, {
onFallback: () => `${hostUUIDField} = '${localHostUUID}'`,

@ -4,17 +4,7 @@ import buildGetRequestHandler from '../buildGetRequestHandler';
export const getNetworkInterface = buildGetRequestHandler(
(request, buildQueryOptions) => {
let localHostUUID: string;
try {
localHostUUID = getLocalHostUUID();
} catch (subError) {
console.log(`Failed to get local host UUID; CAUSE: ${subError}`);
throw subError;
}
console.log(`localHostUUID=[${localHostUUID}]`);
const localHostUUID: string = getLocalHostUUID();
if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => {

@ -44,7 +44,7 @@ export const getServerDetail: RequestHandler = (request, response) => {
try {
requestHostUUID = getLocalHostUUID();
} catch (subError) {
console.log(`Failed to get local host UUID; CAUSE: ${subError}`);
console.log(subError);
response.status(500).send();

Loading…
Cancel
Save