File tree Expand file tree Collapse file tree 1 file changed +25
-20
lines changed
Expand file tree Collapse file tree 1 file changed +25
-20
lines changed Original file line number Diff line number Diff line change @@ -13,26 +13,31 @@ type TResponse = IProductCheckout | Empty;
1313const 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 : {
You can’t perform that action at this time.
0 commit comments