Skip to content

Commit 7208562

Browse files
Merge pull request #50 from Dynatrace/DREL-6473-merge-frontend-logs
add logging statement with timestamp
2 parents ef2c418 + 9309f56 commit 7208562

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/frontend/pages/api/checkout.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,31 @@ type TResponse = IProductCheckout | Empty;
1313
const handler = async ({ method, body, query }: NextApiRequest, res: NextApiResponse<TResponse>) => {
1414
switch (method) {
1515
case 'POST': {
16-
const { currencyCode = '' } = query;
17-
const orderData = body as PlaceOrderRequest;
18-
const { order: { items = [], ...order } = {} } = await CheckoutGateway.placeOrder(orderData);
19-
20-
const productList: IProductCheckoutItem[] = await Promise.all(
21-
items.map(async ({ item: { productId = '', quantity = 0 } = {}, cost }) => {
22-
const product = await ProductCatalogService.getProduct(productId, currencyCode as string);
23-
24-
return {
25-
cost,
26-
item: {
27-
productId,
28-
quantity,
29-
product,
30-
},
31-
};
32-
})
33-
);
34-
35-
return res.status(200).json({ ...order, items: productList });
16+
try {
17+
const { currencyCode = '' } = query;
18+
const orderData = body as PlaceOrderRequest;
19+
const { order: { items = [], ...order } = {} } = await CheckoutGateway.placeOrder(orderData);
20+
21+
const productList: IProductCheckoutItem[] = await Promise.all(
22+
items.map(async ({ item: { productId = '', quantity = 0 } = {}, cost }) => {
23+
const product = await ProductCatalogService.getProduct(productId, currencyCode as string);
24+
25+
return {
26+
cost,
27+
item: {
28+
productId,
29+
quantity,
30+
product,
31+
},
32+
};
33+
})
34+
);
35+
36+
return res.status(200).json({ ...order, items: productList });
37+
} catch (error: any) {
38+
console.error(`[${new Date().toISOString()}]`, error);
39+
throw error;
40+
}
3641
}
3742

3843
default: {

0 commit comments

Comments
 (0)