search-console: vorübergehende Google-Fehler einmal wiederholt und nur als Warnung protokolliert, Portal-Abbruch nach fünf Fehlern in Folge, Zeitbudget 40 Minuten (GlitchTip server-pressekonto 11–14)

Am 06.10.2026 hing die URL Inspection API zeitweise: 28 Zeitüberschreitungen
und 4 × 500, jede einzeln als Fehler gemeldet, der Lauf zog sich über 1¾
Stunden. Neu: SearchConsoleUnavailable für Timeout/5xx/429 (Warnung, Meldung
bleibt fällig), echte Fehler (401/403/400) weiter über report(); FAILURE —
und damit ein Betriebs-Alert — nur bei Abbruch oder ≥ 50 % Fehlern.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-10-06 13:12:29 +00:00
parent 2f02acceaf
commit a90f24a43f
5 changed files with 228 additions and 19 deletions

View file

@ -2,9 +2,13 @@
namespace App\Services\SearchConsole;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\RequestException;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use RuntimeException;
use Throwable;
/**
* Schmaler Client für die URL Inspection API der Google Search Console
@ -59,22 +63,37 @@ class SearchConsoleClient
*/
public function inspect(string $url, string $siteUrl, string $languageCode = 'de-DE'): array
{
$response = Http::withToken($this->accessToken())
->acceptJson()
->timeout(20)
->post(self::INSPECT_URL, [
'inspectionUrl' => $url,
'siteUrl' => $siteUrl,
'languageCode' => $languageCode,
]);
try {
$response = Http::withToken($this->accessToken())
->acceptJson()
->timeout((int) config('search_console.timeout_seconds', 20))
->retry(
1 + (int) config('search_console.retries', 1),
(int) config('search_console.retry_sleep_ms', 3000),
fn (Throwable $e): bool => $e instanceof ConnectionException
|| ($e instanceof RequestException && self::isTransient($e->response)),
throw: false,
)
->post(self::INSPECT_URL, [
'inspectionUrl' => $url,
'siteUrl' => $siteUrl,
'languageCode' => $languageCode,
]);
} catch (ConnectionException $e) {
// Ohne Millisekundenangabe im Text: GlitchTip gruppierte die
// Zeitüberschreitungen sonst nach 20000/20001/20002 ms getrennt.
throw new SearchConsoleUnavailable('URL Inspection API nicht erreichbar (Zeitüberschreitung oder Verbindungsfehler) für '.$url, previous: $e);
}
if (! $response->successful()) {
throw new RuntimeException(sprintf(
$message = sprintf(
'URL Inspection API antwortet mit %d für %s: %s',
$response->status(),
$url,
(string) ($response->json('error.message') ?? $response->body()),
));
);
throw self::isTransient($response) ? new SearchConsoleUnavailable($message) : new RuntimeException($message);
}
$result = $response->json('inspectionResult');
@ -82,6 +101,16 @@ class SearchConsoleClient
return is_array($result) ? $result : [];
}
/**
* Vorübergehend: Google-seitiger Fehler (5xx) oder Drosselung (429).
* Alles andere (401/403/400) ist Konfiguration oder Anfrage und wird
* nicht wiederholt.
*/
private static function isTransient(Response $response): bool
{
return $response->serverError() || $response->status() === 429;
}
/**
* Zugriffstoken des Service-Kontos, 50 Minuten gecacht (Gültigkeit 60).
*/