@@ -48,9 +48,9 @@ async function fetchProduct(sku, config) {
48
48
throw errorWithResponse ( resp . status , 'failed to fetch product' ) ;
49
49
}
50
50
51
- const json = await resp . json ( ) ;
52
51
try {
53
- const [ productData ] = json . data ?. products ?? [ ] ;
52
+ const json = await resp . json ( ) ;
53
+ const [ productData ] = json ?. data ?. products ?? [ ] ;
54
54
if ( ! productData ) {
55
55
throw errorWithResponse ( 404 , 'could not find product' , json . errors ) ;
56
56
}
@@ -93,9 +93,9 @@ async function fetchVariants(sku, config) {
93
93
throw errorWithResponse ( resp . status , 'failed to fetch variants' ) ;
94
94
}
95
95
96
- const json = await resp . json ( ) ;
97
96
try {
98
- const { variants } = json . data . variants ;
97
+ const json = await resp . json ( ) ;
98
+ const { variants } = json ?. data ?. variants ?? { } ;
99
99
return variantsAdapter ( variants ) ;
100
100
} catch ( e ) {
101
101
console . error ( 'failed to parse variants: ' , e ) ;
@@ -134,10 +134,10 @@ async function lookupProductSKU(urlkey, config) {
134
134
throw errorWithResponse ( resp . status , 'failed to fetch product sku' ) ;
135
135
}
136
136
137
- const json = await resp . json ( ) ;
138
137
try {
139
- const [ product ] = json . data ?. products ?. items ?? [ ] ;
140
- if ( ! product ) {
138
+ const json = await resp . json ( ) ;
139
+ const [ product ] = json ?. data ?. products ?. items ?? [ ] ;
140
+ if ( ! product ?. sku ) {
141
141
throw errorWithResponse ( 404 , 'could not find product sku' , json . errors ) ;
142
142
}
143
143
return product . sku ;
0 commit comments