fix(api): preserve error semantics in getProductBySlug distinguishing 404 from 5xx [FE-010]
This commit is contained in:
1 parent
1c38b95fb0
commit
14c45e4f6c
1 file changed
+11
-2
@@ -273,8 +273,17 @@ export class ProductService {
|
||||
}
|
||||
const response = await api.get(`/products/${slug}`);
|
||||
return this.mapBackendToFrontend(response.data);
|
||||
} catch (error) {
|
||||
console.error(`[ProductService] Failed to fetch product ${slug}:`, error);
|
||||
} catch (error: any) {
|
||||
// Differentiate 404 (legitimate not found) from network/5xx server failure
|
||||
const status = error?.response?.status || (String(error?.message).includes('404') ? 404 : null);
|
||||
if (status === 404) {
|
||||
return null;
|
||||
}
|
||||
console.error(`[ProductService] Upstream error fetching product ${slug}:`, error);
|
||||
// Re-throw upstream server errors so Next.js ErrorBoundary renders retryable state instead of fake 404
|
||||
if (typeof window === 'undefined') {
|
||||
throw error;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user