{"record":{"id":"41abe549e2a43295","repo":"JuliusBrussee/caveman","slug":"githubapp-revoke-token-http-d-s","errorCode":null,"errorMessage":"githubapp: revoke token: HTTP %d: %s","messagePattern":"githubapp: revoke token: HTTP (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":238,"sourceCode":"\tif err := json.Unmarshal(raw, &out); err != nil {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: decode token response: %w\", err)\n\t}\n\tif out.Token == \"\" {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: token response carried no token\")\n\t}\n\treturn out, nil\n}\n\n// RevokeToken DELETEs /installation/token authenticated with the token itself —\n// the job-end \"drop all agency\" step. A best-effort revoke; the ~1h natural\n// expiry is the backstop.\nfunc (a *App) RevokeToken(ctx context.Context, token string) error {\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+token, http.MethodDelete, \"/installation/token\", nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif status != http.StatusNoContent {\n\t\treturn fmt.Errorf(\"githubapp: revoke token: HTTP %d: %s\", status, snippet(raw))\n\t}\n\treturn nil\n}\n\n// Repo is the minimal repo metadata the connect flow stores.\ntype Repo struct {\n\tID            int64  `json:\"id\"`\n\tNodeID        string `json:\"node_id\"`\n\tFullName      string `json:\"full_name\"`\n\tDefaultBranch string `json:\"default_branch\"`\n}\n\n// GetRepo verifies that the installation token can see owner/name and returns the\n// repo's stable node id + default branch. Used by select-repo to confirm the repo\n// truly belongs to the installation before the binding goes 'active'.\nfunc (a *App) GetRepo(ctx context.Context, token, owner, name string) (Repo, error) {\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+token, http.MethodGet,\n\t\t\"/repos/\"+url.PathEscape(owner)+\"/\"+url.PathEscape(name), nil)","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L220-L256","documentation":"RevokeToken deletes an installation access token via DELETE /installation/token and expects HTTP 204 No Content. Any other status is reported with this error, including the status code and a body snippet, so the caller can see exactly why revocation failed.","triggerScenarios":"a.do() returns an HTTP status other than 204 when calling DELETE /installation/token with the token as Bearer credential — e.g. 401 for an expired/invalid token, 404 if the App is not installed, 5xx from GitHub.","commonSituations":"Revoking a token that already expired or was previously revoked; token belongs to a different GitHub App; GitHub outage or rate limiting during teardown of a connection.","solutions":["Log the embedded HTTP status and body snippet; treat 401/404 as 'already invalid' and proceed without failing","Verify the token passed to RevokeToken was minted by this same App (same App ID / private key)","Re-check GitHub API status (status.github.com) if status is 5xx, then retry once","Confirm the token has not already been revoked — installation tokens are single-use for revocation"],"exampleFix":"// before\nif err := app.RevokeToken(ctx, tok); err != nil { return err }\n// after\nif err := app.RevokeToken(ctx, tok); err != nil {\n    var httpErr interface{ Error() string }\n    if strings.Contains(err.Error(), \"HTTP 401\") || strings.Contains(err.Error(), \"HTTP 404\") {\n        return nil // token already invalid\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// caller-side: skip revocation when the token is already known to be expired\nif tokenExpired(installationToken) { return nil }","typeGuard":"func isRevocationAlreadyInvalid(err error) bool {\n    return err != nil && (strings.Contains(err.Error(), \"HTTP 401\") || strings.Contains(err.Error(), \"HTTP 404\"))\n}","tryCatchPattern":"if err := app.RevokeToken(ctx, tok); err != nil {\n    if isRevocationAlreadyInvalid(err) { log.Warn(\"token already invalid; skipping revoke\"); return nil }\n    return fmt.Errorf(\"revoke installation token: %w\", err)\n}","preventionTips":["Revoke tokens promptly after use, before the ~1h installation-token expiry","Never reuse a token across revoke attempts — revocation is one-shot","Treat 401/404 as idempotent success in teardown paths","Monitor GitHub status before bulk revocation jobs"],"tags":["github","http","token-revocation"],"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"}