fix: log errors in writeShopifyIdToSheet and skip 404s in sync-stock
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { authOptions } from '@/lib/auth'
|
||||
import { fetchPendingProducts, findColIndex } from '@/lib/creationSheets'
|
||||
import { findColIndex } from '@/lib/creationSheets'
|
||||
import { getConfig } from '@/lib/shopifySync'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
@@ -86,8 +86,13 @@ export async function POST(req: NextRequest) {
|
||||
try {
|
||||
// Récupérer le variant pour obtenir inventory_item_id
|
||||
const pRes = await fetch(`${baseUrl}/products/${shopifyId}.json?fields=variants`, { headers })
|
||||
if (pRes.status === 404) {
|
||||
// Produit supprimé de Shopify, on ignore silencieusement
|
||||
continue
|
||||
}
|
||||
if (!pRes.ok) {
|
||||
send({ type: 'error', title, message: `Produit ${shopifyId} introuvable (${pRes.status})` })
|
||||
const msg = `Produit ${shopifyId} erreur (${pRes.status})`
|
||||
send({ type: 'error', title, message: msg })
|
||||
errors++
|
||||
continue
|
||||
}
|
||||
@@ -121,6 +126,7 @@ export async function POST(req: NextRequest) {
|
||||
send({ type: 'done', updated, errors })
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
console.error('[sync-stock] fatal:', message)
|
||||
send({ type: 'done', updated: 0, errors: 1, fatalError: message })
|
||||
} finally {
|
||||
controller.close()
|
||||
|
||||
Reference in New Issue
Block a user