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

main
Tsu-ba-me 2 years ago
parent be1332b4f3
commit 6afa296858
  1. 15
      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, spawnSyncOptions,
).stdout; ).stdout;
const getLocalHostUUID = () => const getLocalHostUUID = () => {
execModuleSubroutine('host_uuid', { let result;
try {
result = execModuleSubroutine('host_uuid', {
subModuleName: 'Get', subModuleName: 'Get',
}).stdout; }).stdout;
} catch (subError) {
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`);
}
shout(`localHostUUID=[${result}]`);
return result;
};
export { export {
dbInsertOrUpdateJob as job, dbInsertOrUpdateJob as job,

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

@ -39,7 +39,6 @@ export const getHostConnection = buildGetRequestHandler(
(request, buildQueryOptions) => { (request, buildQueryOptions) => {
const { hostUUIDs: rawHostUUIDs } = request.query; const { hostUUIDs: rawHostUUIDs } = request.query;
let localHostUUID: string;
let rawDatabaseData: { let rawDatabaseData: {
[hostUUID: string]: { [hostUUID: string]: {
host: 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 hostUUIDField = 'ip_add.ip_address_host_uuid';
const localHostUUID: string = getLocalHostUUID();
const { after: condHostUUIDs, before: beforeBuildIDCond } = const { after: condHostUUIDs, before: beforeBuildIDCond } =
buildUnknownIDCondition(rawHostUUIDs, hostUUIDField, { buildUnknownIDCondition(rawHostUUIDs, hostUUIDField, {
onFallback: () => `${hostUUIDField} = '${localHostUUID}'`, onFallback: () => `${hostUUIDField} = '${localHostUUID}'`,

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

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

Loading…
Cancel
Save