{"record":{"id":"72e34e4d02be2c80","repo":"JuliusBrussee/caveman","slug":"githubapp-get-installation-http-d-s","errorCode":null,"errorMessage":"githubapp: get installation: HTTP %d: %s","messagePattern":"githubapp: get installation: HTTP (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":172,"sourceCode":"}\n\n// GetInstallation verifies an installation id against GitHub using the App JWT.\nfunc (a *App) GetInstallation(ctx context.Context, installationID int64) (Installation, error) {\n\tvar out Installation\n\tif installationID <= 0 {\n\t\treturn out, fmt.Errorf(\"githubapp: installation id must be positive\")\n\t}\n\tjwt, err := a.AppJWT()\n\tif err != nil {\n\t\treturn out, err\n\t}\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+jwt, http.MethodGet,\n\t\t\"/app/installations/\"+strconv.FormatInt(installationID, 10), nil)\n\tif err != nil {\n\t\treturn out, err\n\t}\n\tif status != http.StatusOK {\n\t\treturn out, fmt.Errorf(\"githubapp: get installation: HTTP %d: %s\", status, snippet(raw))\n\t}\n\tif err := json.Unmarshal(raw, &out); err != nil {\n\t\treturn out, fmt.Errorf(\"githubapp: decode installation: %w\", err)\n\t}\n\tif out.ID != installationID || out.Account.ID <= 0 || strings.TrimSpace(out.Account.Login) == \"\" {\n\t\treturn Installation{}, fmt.Errorf(\"githubapp: installation response identity mismatch\")\n\t}\n\treturn out, nil\n}\n\n// MintInstallationToken POSTs /app/installations/{id}/access_tokens narrowed to\n// `repos` and `perms`, returning a ~1h token. Defaults (perms nil) are\n// contents:write + pull_requests:write — enough to push a branch and open a draft\n// PR, never to merge.\nfunc (a *App) MintInstallationToken(ctx context.Context, installationID int64, repos []string, perms map[string]string) (InstallationToken, error) {\n\tif installationID <= 0 {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: installation id must be positive\")\n\t}","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L154-L190","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","For 401, verify the App ID and private key used to mint the JWT; ensure the JWT is fresh (<10 min old)","For 403, check the installation's suspension status in the GitHub App settings","For 5xx, retry with backoff; treat as transient"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if installationID <= 0 { return fmt.Errorf(\"invalid installation id %d\", installationID) }","typeGuard":"func isHTTPStatusErr(err error, codes ...int) bool {\n\tif err == nil { return false }\n\tfor _, c := range codes {\n\t\tif strings.Contains(err.Error(), fmt.Sprintf(\"HTTP %d:\", c)) { return true }\n\t}\n\treturn false\n}","tryCatchPattern":"inst, err := app.GetInstallation(ctx, id)\nif err != nil {\n\tif isHTTPStatusErr(err, 404) { /* installation gone: re-discover ID */ }\n\tif isHTTPStatusErr(err, 401, 403) { /* credentials/suspension: do not retry */ }\n\tif isHTTPStatusErr(err, 500, 502, 503) { /* retry with backoff */ }\n\treturn err\n}","preventionTips":["Re-discover installation IDs after app reinstall (they change)","Keep App JWTs fresh; verify App ID and private key","Monitor installation suspension state in the GitHub App settings"],"tags":["github-app","http","api"],"backgroundTag":"http-error-response","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}