wtfutil/wtf · error

%s

Error message

%s

What it means

apiRequest in the HackerNews module returns the raw HTTP status line (e.g. '503 Service Unavailable') as the error whenever the API responds with a status outside 200-299. It is a generic transport-level failure guard: the request completed, but the server rejected it. The body is discarded, so the real reason (if any) is only in the status code.

Source

Thrown at modules/hackernews/client.go:70

	apiEndpoint = "https://hacker-news.firebaseio.com/v0/"
)

func apiRequest(path string) ([]byte, error) {
	req, err := http.NewRequest("GET", apiEndpoint+path+".json", http.NoBody)
	if err != nil {
		return nil, err
	}

	httpClient := &http.Client{}
	resp, err := httpClient.Do(req)
	if err != nil {
		return nil, err
	}

	defer func() { _ = resp.Body.Close() }()

	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		return nil, fmt.Errorf("%s", resp.Status)
	}

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	return body, nil
}

View on GitHub (pinned to bb838c1ccb)

Solutions

  1. Check the error message for the status code and retry with backoff for 429/5xx
  2. Verify the client's base URL / endpoint configuration is correct
  3. Check network connectivity and any proxy settings
  4. Confirm the upstream service status before further debugging
Defensive patterns

Strategy: try-catch

Try / catch

msgs, err := widget.GetMessages(room)
if err != nil {
    log.Printf("HN api error (check status in msg): %v", err)
    return // keep last known data, retry later
}

Prevention

When it happens

Trigger: Any GetMessages or GetRoom call where the HN/Firebase-backed endpoint returns a 4xx/5xx status: rate limiting (429), server errors (5xx), wrong/redirected URL, or a proxy returning 404/403.

Common situations: HackerNews/Firebase API outage or throttling under heavy polling, corporate proxy intercepting requests, misconfigured base URL pointing to a wrong host, or transient DNS/network failures surfacing as gateway 502/504.

Related errors


AI-assisted analysis of wtfutil/wtf@bb838c1ccb (2026-09-03). Data as JSON: /api/errors/611d2f2467db1a5d. Report an issue: GitHub.