JuliusBrussee/caveman · error

githubapp: mint token: HTTP

Error message

githubapp: mint token: HTTP %d: %s

What it means

POST /app/installations/{id}/access_tokens returned a status other than 201 (the expected Created status). The error includes the status and a response-body snippet. Any non-201 means no token was minted and the library fails closed.

Solutions

  1. Read the status and body snippet: 404 → wrong installation ID or app uninstalled; 403 → suspended or JWT issue; 422 → requested permissions not granted to the app
  2. Verify App ID/private key and JWT freshness for 401
  3. For 422, align requested perms with the app's registered permissions
  4. For 5xx, retry with exponential backoff
Defensive patterns

Strategy: retry

Validate before calling

if installationID <= 0 || len(repos) != 1 { /* validate inputs before the call */ }

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

tok, err := app.MintInstallationToken(ctx, id, []string{repo}, nil)
if err != nil {
	switch {
	case isHTTPStatusErr(err, 401):
		// refresh App JWT credentials
	case isHTTPStatusErr(err, 403):
		// installation suspended: surface to operator
	case isHTTPStatusErr(err, 404):
		// installation removed: re-discover ID
	case isHTTPStatusErr(err, 422):
		// perms exceed app registration: reduce perms
	case isHTTPStatusErr(err, 500, 502, 503, 504):
		// transient: retry with backoff
	}
	return err
}

Prevention

When it happens

Trigger: App.MintInstallationToken where the App JWT is rejected (401), the installation does not exist (404), the installation is suspended (403), permissions exceed what the app is allowed (422), or GitHub returns 5xx.

Common situations: Expired/incorrect App credentials; app uninstalled or suspended on the target org; requesting permissions the app's registration doesn't declare; transient 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/ccb88a37132d31a1. Report an issue: GitHub.

Appendix: source

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

	scopedPermissions := make(map[string]string, len(perms))
	for name, level := range perms {
		if !allowedPermissions[name] || (level != "read" && level != "write") {
			return InstallationToken{}, fmt.Errorf("githubapp: permission %q=%q exceeds the least-agency allowlist", name, level)
		}
		scopedPermissions[name] = level
	}
	jwt, err := a.AppJWT()
	if err != nil {
		return InstallationToken{}, err
	}
	body := map[string]any{"permissions": scopedPermissions, "repositories": []string{repository}}
	status, raw, err := a.do(ctx, "Bearer "+jwt, http.MethodPost,
		"/app/installations/"+strconv.FormatInt(installationID, 10)+"/access_tokens", body)
	if err != nil {
		return InstallationToken{}, err
	}
	if status != http.StatusCreated {
		return InstallationToken{}, fmt.Errorf("githubapp: mint token: HTTP %d: %s", status, snippet(raw))
	}
	var out InstallationToken
	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

View on GitHub (pinned to 3ee70a1026)