JuliusBrussee/caveman · error

githubapp: get installation: HTTP

Error message

githubapp: get installation: HTTP %d: %s

What it means

GitHub's GET /app/installations/{id} endpoint returned a status other than 200. The error carries the HTTP status and a snippet of the response body so the caller can see why GitHub rejected the request. This is a fail-closed guard: without a 200 the library will not trust or parse the response.

Solutions

  1. Check the status/body in the error: 404 means the ID is wrong or the app was uninstalled — re-list installations via GET /app/installations
  2. For 401, verify the App ID and private key used to mint the JWT; ensure the JWT is fresh (<10 min old)
  3. For 403, check the installation's suspension status in the GitHub App settings
  4. For 5xx, retry with backoff; treat as transient
Defensive patterns

Strategy: retry

Validate before calling

if installationID <= 0 { return fmt.Errorf("invalid installation id %d", installationID) }

Type guard

func isHTTPStatusErr(err error, codes ...int) bool {
	if err == nil { return false }
	for _, c := range codes {
		if strings.Contains(err.Error(), fmt.Sprintf("HTTP %d:", c)) { return true }
	}
	return false
}

Try / catch

inst, err := app.GetInstallation(ctx, id)
if err != nil {
	if isHTTPStatusErr(err, 404) { /* installation gone: re-discover ID */ }
	if isHTTPStatusErr(err, 401, 403) { /* credentials/suspension: do not retry */ }
	if isHTTPStatusErr(err, 500, 502, 503) { /* retry with backoff */ }
	return err
}

Prevention

When it happens

Trigger: App.GetInstallation with a valid positive ID where the App JWT request yields 404 (installation not found or app not installed on that account), 401 (bad/expired JWT or wrong App ID), 403 (installation suspended), or 5xx from GitHub.

Common situations: Wrong installation ID after reinstalling the app (IDs change on uninstall/reinstall); App JWT misconfigured (wrong private key or app ID); installation suspended or revoked; GitHub incidents.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/72e34e4d02be2c80. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/githubapp/githubapp.go:172

}

// GetInstallation verifies an installation id against GitHub using the App JWT.
func (a *App) GetInstallation(ctx context.Context, installationID int64) (Installation, error) {
	var out Installation
	if installationID <= 0 {
		return out, fmt.Errorf("githubapp: installation id must be positive")
	}
	jwt, err := a.AppJWT()
	if err != nil {
		return out, err
	}
	status, raw, err := a.do(ctx, "Bearer "+jwt, http.MethodGet,
		"/app/installations/"+strconv.FormatInt(installationID, 10), nil)
	if err != nil {
		return out, err
	}
	if status != http.StatusOK {
		return out, fmt.Errorf("githubapp: get installation: HTTP %d: %s", status, snippet(raw))
	}
	if err := json.Unmarshal(raw, &out); err != nil {
		return out, fmt.Errorf("githubapp: decode installation: %w", err)
	}
	if out.ID != installationID || out.Account.ID <= 0 || strings.TrimSpace(out.Account.Login) == "" {
		return Installation{}, fmt.Errorf("githubapp: installation response identity mismatch")
	}
	return out, nil
}

// MintInstallationToken POSTs /app/installations/{id}/access_tokens narrowed to
// `repos` and `perms`, returning a ~1h token. Defaults (perms nil) are
// contents:write + pull_requests:write — enough to push a branch and open a draft
// PR, never to merge.
func (a *App) MintInstallationToken(ctx context.Context, installationID int64, repos []string, perms map[string]string) (InstallationToken, error) {
	if installationID <= 0 {
		return InstallationToken{}, fmt.Errorf("githubapp: installation id must be positive")
	}

View on GitHub (pinned to 3ee70a1026)