From 7e9c43f2bf40ee21e8d4c007330b0d2341551159 Mon Sep 17 00:00:00 2001 From: Malek Tellissi Date: Fri, 11 Sep 2026 02:54:44 +0200 Subject: [PATCH] Improve Shopify sync error logging Log clear hint for 403 (IP whitelist), 401, 429, 5xx. Commands exit with failure and print error when API returns no data. Co-Authored-By: Claude Sonnet 4.6 --- app/Console/Commands/ShopifyMap.php | 5 +++++ app/Console/Commands/ShopifySync.php | 5 +++++ app/Services/ShopifyService.php | 14 +++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/ShopifyMap.php b/app/Console/Commands/ShopifyMap.php index df67223..e3e509e 100644 --- a/app/Console/Commands/ShopifyMap.php +++ b/app/Console/Commands/ShopifyMap.php @@ -16,6 +16,11 @@ class ShopifyMap extends Command $dryRun = $this->option('dry-run'); $variants = $shopify->getAllVariants(); + if (empty($variants)) { + $this->error('Keine Varianten von Shopify erhalten — API-Aufruf fehlgeschlagen (Details im Log).'); + return self::FAILURE; + } + $this->info('Shopify-Varianten geladen: ' . count($variants)); $mapped = 0; diff --git a/app/Console/Commands/ShopifySync.php b/app/Console/Commands/ShopifySync.php index cc50003..f36cf66 100644 --- a/app/Console/Commands/ShopifySync.php +++ b/app/Console/Commands/ShopifySync.php @@ -18,6 +18,11 @@ class ShopifySync extends Command $dryRun = $this->option('dry-run'); $variants = $shopify->getAllVariants(); + if (empty($variants)) { + $this->error('Keine Varianten von Shopify erhalten — API-Aufruf fehlgeschlagen (Details im Log).'); + return self::FAILURE; + } + $added = 0; $removed = 0; $inSync = 0; diff --git a/app/Services/ShopifyService.php b/app/Services/ShopifyService.php index f58af45..6bdbc0c 100644 --- a/app/Services/ShopifyService.php +++ b/app/Services/ShopifyService.php @@ -31,7 +31,19 @@ class ShopifyService $response = Http::withHeader('X-Shopify-Access-Token', $this->token)->get($url); if ($response->failed()) { - Log::error('Shopify API error', ['status' => $response->status(), 'body' => $response->body()]); + $status = $response->status(); + $hint = match (true) { + $status === 401 => 'Access Token ungültig oder fehlt', + $status === 403 => 'IP-Whitelist: VPS-IP ist in Shopify nicht freigeschalten', + $status === 429 => 'Rate Limit überschritten', + $status >= 500 => 'Shopify-seitiger Fehler', + default => 'Unbekannter Fehler', + }; + Log::error("Shopify Sync fehlgeschlagen: {$hint}", [ + 'status' => $status, + 'url' => $url, + 'body' => $response->body(), + ]); break; }