Skip to content

Commit

Permalink
chore(cb2-11044): remove try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruairidh-BJSS committed May 2, 2024
1 parent 97b7c30 commit ab93a47
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 76 deletions.
114 changes: 58 additions & 56 deletions src/services/CertificateGenerationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,67 +804,67 @@ class CertificateGenerationService {

return this.lambdaClient
.invoke(invokeParams)
.then( async (
response: InvocationResponse
) => {
console.warn("validateInvocationResponse called in getOdometerHistory");
const payload: any = await this.lambdaClient.validateInvocationResponse(response);
// TODO: convert to correct type
const testResults: any[] = JSON.parse(payload.body);

if (!testResults || testResults.length === 0) {
throw new HTTPError(
400,
`${ERRORS.LAMBDA_INVOCATION_BAD_DATA} ${JSON.stringify(payload)}.`
);
}
// Sort results by testEndTimestamp
testResults.sort((first: any, second: any): number => {
if (
moment(first.testEndTimestamp).isBefore(second.testEndTimestamp)
) {
return 1;
}

if (
moment(first.testEndTimestamp).isAfter(second.testEndTimestamp)
) {
return -1;
}

return 0;
});
.then(async (
response: InvocationResponse
) => {
console.warn("validateInvocationResponse called in getOdometerHistory");
const payload: any = await this.lambdaClient.validateInvocationResponse(response);
// TODO: convert to correct type
const testResults: any[] = JSON.parse(payload.body);

// Remove the first result as it should be the current one.
testResults.shift();
if (!testResults || testResults.length === 0) {
throw new HTTPError(
400,
`${ERRORS.LAMBDA_INVOCATION_BAD_DATA} ${JSON.stringify(payload)}.`
);
}
// Sort results by testEndTimestamp
testResults.sort((first: any, second: any): number => {
if (
moment(first.testEndTimestamp).isBefore(second.testEndTimestamp)
) {
return 1;
}

// Set the array to only submitted tests (exclude cancelled)
const submittedTests = testResults.filter((testResult) => {
return testResult.testStatus === "submitted";
});
if (
moment(first.testEndTimestamp).isAfter(second.testEndTimestamp)
) {
return -1;
}

const filteredTestResults = submittedTests
.filter(({ testTypes }) =>
testTypes?.some(
(testType: ITestType) =>
testType.testTypeClassification ===
"Annual With Certificate" &&
(testType.testResult === "pass" ||
testType.testResult === "prs")
)
return 0;
});

// Remove the first result as it should be the current one.
testResults.shift();

// Set the array to only submitted tests (exclude cancelled)
const submittedTests = testResults.filter((testResult) => {
return testResult.testStatus === "submitted";
});

const filteredTestResults = submittedTests
.filter(({ testTypes }) =>
testTypes?.some(
(testType: ITestType) =>
testType.testTypeClassification ===
"Annual With Certificate" &&
(testType.testResult === "pass" ||
testType.testResult === "prs")
)
.slice(0, 3); // Only last three entries are used for the history.
)
.slice(0, 3); // Only last three entries are used for the history.

return {
OdometerHistoryList: filteredTestResults.map((testResult) => {
return {
value: testResult.odometerReading,
unit: testResult.odometerReadingUnits,
date: moment(testResult.testEndTimestamp).format("DD.MM.YYYY"),
};
}),
};
}
return {
OdometerHistoryList: filteredTestResults.map((testResult) => {
return {
value: testResult.odometerReading,
unit: testResult.odometerReadingUnits,
date: moment(testResult.testEndTimestamp).format("DD.MM.YYYY"),
};
}),
};
}
)
.catch((error: ServiceException | Error) => {
console.log(error);
Expand Down Expand Up @@ -1048,6 +1048,8 @@ class CertificateGenerationService {
throw new HTTPError(400, `${ERRORS.LAMBDA_INVOCATION_BAD_DATA} ${JSON.stringify(payload)}.`);
}
defects = defectsParsed;
console.log("retries ~: ", retries);
console.log("defects ~: ", defects);
return defects;
} catch (error) {
retries++;
Expand Down
6 changes: 1 addition & 5 deletions src/services/LambdaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ class LambdaService {
public async invoke(
params: InvocationRequest
): Promise<InvocationResponse> {
try {
return await this.lambdaClient.send(new InvokeCommand(params));
} catch (err) {
throw err;
}
return await this.lambdaClient.send(new InvokeCommand(params));
}

/**
Expand Down
18 changes: 3 additions & 15 deletions src/services/S3BucketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ class S3BucketService {
Metadata: metadata,
});

try {
return await this.s3Client.send(command);
} catch (err) {
throw err;
}
return await this.s3Client.send(command);
}

/**
Expand All @@ -58,11 +54,7 @@ class S3BucketService {
Key: `${process.env.BRANCH}/${fileName}`,
});

try {
return this.s3Client.send(command);
} catch (err) {
throw err;
}
return this.s3Client.send(command);
}

/**
Expand All @@ -79,11 +71,7 @@ class S3BucketService {
Key: `${process.env.BRANCH}/${fileName}`,
});

try {
return this.s3Client.send(command);
} catch (err) {
throw err;
}
return this.s3Client.send(command);
}
}

Expand Down

0 comments on commit ab93a47

Please sign in to comment.