Skip to content

Commit 22706c6

Browse files
Log errors but do not fail for new allocations
1 parent 81e9a1a commit 22706c6

2 files changed

Lines changed: 35 additions & 26 deletions

File tree

lambdas/supplier-allocator/src/handler/__tests__/allocate-handler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe("allocate-handler", () => {
257257
() => {},
258258
)) as SQSBatchResponse;
259259

260-
expect(result.batchItemFailures).toHaveLength(1);
260+
expect(result.batchItemFailures).toHaveLength(0);
261261
expect(deps.logger.error).toHaveBeenCalled();
262262
});
263263

lambdas/supplier-allocator/src/handler/allocate-handler.ts

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,45 @@ function validateType(event: unknown) {
5858
}
5959

6060
async function getSupplierFromConfig(letterEvent: PreparedEvents, deps: Deps) {
61-
const variantDetails: LetterVariant = await getVariantDetails(
62-
letterEvent.data.letterVariantId,
63-
deps,
64-
);
65-
66-
const volumeGroupDetails: VolumeGroup = await getVolumeGroupDetails(
67-
variantDetails.volumeGroupId,
68-
deps,
69-
);
70-
71-
const supplierAllocations: SupplierAllocation[] =
72-
await getSupplierAllocationsForVolumeGroup(
61+
try {
62+
const variantDetails: LetterVariant = await getVariantDetails(
63+
letterEvent.data.letterVariantId,
64+
deps,
65+
);
66+
67+
const volumeGroupDetails: VolumeGroup = await getVolumeGroupDetails(
7368
variantDetails.volumeGroupId,
7469
deps,
75-
variantDetails.supplierId,
7670
);
7771

78-
const supplierDetails: Supplier[] = await getSupplierDetails(
79-
supplierAllocations,
80-
deps,
81-
);
82-
deps.logger.info({
83-
description: "Fetched supplier details for supplier allocations",
84-
variantId: letterEvent.data.letterVariantId,
85-
volumeGroupId: volumeGroupDetails.id,
86-
supplierAllocationIds: supplierAllocations.map((a) => a.id),
87-
supplierDetails,
88-
});
72+
const supplierAllocations: SupplierAllocation[] =
73+
await getSupplierAllocationsForVolumeGroup(
74+
variantDetails.volumeGroupId,
75+
deps,
76+
variantDetails.supplierId,
77+
);
78+
79+
const supplierDetails: Supplier[] = await getSupplierDetails(
80+
supplierAllocations,
81+
deps,
82+
);
83+
deps.logger.info({
84+
description: "Fetched supplier details for supplier allocations",
85+
variantId: letterEvent.data.letterVariantId,
86+
volumeGroupId: volumeGroupDetails.id,
87+
supplierAllocationIds: supplierAllocations.map((a) => a.id),
88+
supplierDetails,
89+
});
8990

90-
return supplierDetails;
91+
return supplierDetails;
92+
} catch (error) {
93+
deps.logger.error({
94+
description: "Error fetching supplier from config",
95+
err: error,
96+
variantId: letterEvent.data.letterVariantId,
97+
});
98+
return [];
99+
}
91100
}
92101

93102
function getSupplier(letterEvent: PreparedEvents, deps: Deps): SupplierSpec {

0 commit comments

Comments
 (0)