JuliusBrussee/caveman · error

githubapp: revoke token: HTTP

Error message

githubapp: revoke token: HTTP %d: %s

What it means

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.

Solutions

  1. Log the embedded HTTP status and body snippet; treat 401/404 as 'already invalid' and proceed without failing
  2. Verify the token passed to RevokeToken was minted by this same App (same App ID / private key)
  3. Re-check GitHub API status (status.github.com) if status is 5xx, then retry once
  4. Confirm the token has not already been revoked — installation tokens are single-use for revocation

Example fix

// before
if err := app.RevokeToken(ctx, tok); err != nil { return err }
// after
if err := app.RevokeToken(ctx, tok); err != nil {
    var httpErr interface{ Error() string }
    if strings.Contains(err.Error(), "HTTP 401") || strings.Contains(err.Error(), "HTTP 404") {
        return nil // token already invalid
    }
    return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

// caller-side: skip revocation when the token is already known to be expired
if tokenExpired(installationToken) { return nil }

Type guard

func isRevocationAlreadyInvalid(err error) bool {
    return err != nil && (strings.Contains(err.Error(), "HTTP 401") || strings.Contains(err.Error(), "HTTP 404"))
}

Try / catch

if err := app.RevokeToken(ctx, tok); err != nil {
    if isRevocationAlreadyInvalid(err) { log.Warn("token already invalid; skipping revoke"); return nil }
    return fmt.Errorf("revoke installation token: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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/41abe549e2a43295. Report an issue: GitHub.

Appendix: source

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

	if err := json.Unmarshal(raw, &out); err != nil {
		return InstallationToken{}, fmt.Errorf("githubapp: decode token response: %w", err)
	}
	if out.Token == "" {
		return InstallationToken{}, fmt.Errorf("githubapp: token response carried no token")
	}
	return out, nil
}

// RevokeToken DELETEs /installation/token authenticated with the token itself —
// the job-end "drop all agency" step. A best-effort revoke; the ~1h natural
// expiry is the backstop.
func (a *App) RevokeToken(ctx context.Context, token string) error {
	status, raw, err := a.do(ctx, "Bearer "+token, http.MethodDelete, "/installation/token", nil)
	if err != nil {
		return err
	}
	if status != http.StatusNoContent {
		return fmt.Errorf("githubapp: revoke token: HTTP %d: %s", status, snippet(raw))
	}
	return nil
}

// Repo is the minimal repo metadata the connect flow stores.
type Repo struct {
	ID            int64  `json:"id"`
	NodeID        string `json:"node_id"`
	FullName      string `json:"full_name"`
	DefaultBranch string `json:"default_branch"`
}

// GetRepo verifies that the installation token can see owner/name and returns the
// repo's stable node id + default branch. Used by select-repo to confirm the repo
// truly belongs to the installation before the binding goes 'active'.
func (a *App) GetRepo(ctx context.Context, token, owner, name string) (Repo, error) {
	status, raw, err := a.do(ctx, "Bearer "+token, http.MethodGet,
		"/repos/"+url.PathEscape(owner)+"/"+url.PathEscape(name), nil)

View on GitHub (pinned to 3ee70a1026)