fix(hetzner): throw on non-2xx responses to prevent silent failures (#2105)

hetznerApi() was returning raw response text on non-2xx final attempts
instead of throwing, identical to the bug fixed in daytonaApi() by PR #2102.

Impact: a 5xx when fetching SSH keys caused createServer() to receive null
from parseJsonObj(), fall back to an empty SSH key list, and provision a
server the user cannot SSH into -- with no error or warning.

Fix matches the pattern from lightsailRest() (AWS) and PR #2102 (Daytona):
throw with the HTTP status code after retries exhaust on any !resp.ok response.

Agent: code-health

Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
A 2026-03-02 05:36:42 -08:00 committed by GitHub
parent 23acf62e1a
commit c61a9c6085
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -76,6 +76,9 @@ async function hetznerApi(method: string, endpoint: string, body?: string, maxRe
interval = Math.min(interval * 2, 30);
continue;
}
if (!resp.ok) {
throw new Error(`Hetzner API error (HTTP ${resp.status}): ${text.slice(0, 200)}`);
}
return text;
} catch (err) {
if (attempt >= maxRetries) {