Skip to content

Commit 97ccad0

Browse files
error checking
1 parent 4fbcc9f commit 97ccad0

1 file changed

Lines changed: 40 additions & 20 deletions

File tree

internal/datastore/src/supplier-quotas-repository.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,26 @@ export class SupplierQuotasRepository {
4949
}
5050

5151
async putOverallAllocation(allocation: OverallAllocation): Promise<void> {
52-
await this.ddbClient.send(
53-
new PutCommand({
54-
TableName: this.config.supplierQuotasTableName,
55-
Item: ItemForRecord(
56-
"overall-allocation",
57-
allocation.id,
58-
$OverallAllocation.parse(allocation),
59-
),
60-
}),
61-
);
52+
try {
53+
const parsedAllocation = $OverallAllocation.parse(allocation);
54+
await this.ddbClient.send(
55+
new PutCommand({
56+
TableName: this.config.supplierQuotasTableName,
57+
Item: ItemForRecord(
58+
"overall-allocation",
59+
allocation.id,
60+
parsedAllocation,
61+
),
62+
}),
63+
);
64+
} catch (error) {
65+
if (error instanceof Error) {
66+
throw new Error(
67+
`Failed to put overall allocation for id ${allocation.id}: ${error.message}`,
68+
);
69+
}
70+
throw error;
71+
}
6272
}
6373

6474
// Update the overallAllocation table updating the allocations array for a given volume group
@@ -112,16 +122,26 @@ export class SupplierQuotasRepository {
112122
}
113123

114124
async putDailyAllocation(allocation: DailyAllocation): Promise<void> {
115-
await this.ddbClient.send(
116-
new PutCommand({
117-
TableName: this.config.supplierQuotasTableName,
118-
Item: ItemForRecord(
119-
"daily-allocation",
120-
`${allocation.volumeGroup}#DATE#${allocation.date}`,
121-
$DailyAllocation.parse(allocation),
122-
),
123-
}),
124-
);
125+
try {
126+
const parsedAllocation = $DailyAllocation.parse(allocation);
127+
await this.ddbClient.send(
128+
new PutCommand({
129+
TableName: this.config.supplierQuotasTableName,
130+
Item: ItemForRecord(
131+
"daily-allocation",
132+
`${allocation.volumeGroup}#DATE#${allocation.date}`,
133+
parsedAllocation,
134+
),
135+
}),
136+
);
137+
} catch (error) {
138+
if (error instanceof Error) {
139+
throw new Error(
140+
`Failed to put daily allocation for volume group ${allocation.volumeGroup} and date ${allocation.date}: ${error.message}`,
141+
);
142+
}
143+
throw error;
144+
}
125145
}
126146

127147
async updateDailyAllocation(

0 commit comments

Comments
 (0)