fix(webhook): treat HTTP 409 (rebuild already running) as success, not error
The pmtiles-webhook returns 409 when a rebuild is already in progress. Previously this was treated as a failure, showing 'Webhook PMTiles indisponibil' error to the user. Now 409 is handled as a valid state with appropriate messaging. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,10 +9,10 @@ const WEBHOOK_URL = process.env.N8N_WEBHOOK_URL || "";
|
||||
export async function firePmtilesRebuild(
|
||||
event: string,
|
||||
metadata?: Record<string, unknown>,
|
||||
): Promise<boolean> {
|
||||
): Promise<{ ok: boolean; alreadyRunning?: boolean }> {
|
||||
if (!WEBHOOK_URL) {
|
||||
console.warn("[pmtiles-webhook] N8N_WEBHOOK_URL not configured — skipping rebuild trigger");
|
||||
return false;
|
||||
return { ok: false };
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -27,13 +27,17 @@ export async function firePmtilesRebuild(
|
||||
});
|
||||
if (res.ok) {
|
||||
console.log(`[pmtiles-webhook] Rebuild triggered (event: ${event}, HTTP ${res.status})`);
|
||||
return true;
|
||||
return { ok: true };
|
||||
}
|
||||
if (res.status === 409) {
|
||||
console.log(`[pmtiles-webhook] Rebuild already running (event: ${event})`);
|
||||
return { ok: true, alreadyRunning: true };
|
||||
}
|
||||
console.warn(`[pmtiles-webhook] Webhook returned HTTP ${res.status}`);
|
||||
return false;
|
||||
return { ok: false };
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
console.warn(`[pmtiles-webhook] Failed: ${msg}`);
|
||||
return false;
|
||||
return { ok: false };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user