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:
parent
17dceec4f7
commit
df557e419b
5 changed files with 228 additions and 19 deletions
|
|
@ -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).
|
||||
*/
|
||||
|
|
|
|||
14
app/Services/SearchConsole/SearchConsoleUnavailable.php
Normal file
14
app/Services/SearchConsole/SearchConsoleUnavailable.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\SearchConsole;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Google antwortet vorübergehend nicht (Zeitüberschreitung, Verbindungsfehler,
|
||||
* 5xx, 429) — auch nach der Wiederholung. Kein Fehler der Anwendung: die
|
||||
* Meldung bleibt fällig und wird beim nächsten Lauf erneut geprüft. Der
|
||||
* Befehl protokolliert das als Warnung statt es zu melden (GlitchTip
|
||||
* server-pressekonto, Issues 11–14, 06.10.2026).
|
||||
*/
|
||||
class SearchConsoleUnavailable extends RuntimeException {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue