{"record":{"id":"ccb88a37132d31a1","repo":"JuliusBrussee/caveman","slug":"githubapp-mint-token-http-d-s","errorCode":null,"errorMessage":"githubapp: mint token: HTTP %d: %s","messagePattern":"githubapp: mint token: HTTP (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":217,"sourceCode":"\tscopedPermissions := make(map[string]string, len(perms))\n\tfor name, level := range perms {\n\t\tif !allowedPermissions[name] || (level != \"read\" && level != \"write\") {\n\t\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: permission %q=%q exceeds the least-agency allowlist\", name, level)\n\t\t}\n\t\tscopedPermissions[name] = level\n\t}\n\tjwt, err := a.AppJWT()\n\tif err != nil {\n\t\treturn InstallationToken{}, err\n\t}\n\tbody := map[string]any{\"permissions\": scopedPermissions, \"repositories\": []string{repository}}\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+jwt, http.MethodPost,\n\t\t\"/app/installations/\"+strconv.FormatInt(installationID, 10)+\"/access_tokens\", body)\n\tif err != nil {\n\t\treturn InstallationToken{}, err\n\t}\n\tif status != http.StatusCreated {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: mint token: HTTP %d: %s\", status, snippet(raw))\n\t}\n\tvar out InstallationToken\n\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","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L199-L235","documentation":"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.","triggerScenarios":"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.","commonSituations":"Expired/incorrect App credentials; app uninstalled or suspended on the target org; requesting permissions the app's registration doesn't declare; transient GitHub incidents.","solutions":["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","Verify App ID/private key and JWT freshness for 401","For 422, align requested perms with the app's registered permissions","For 5xx, retry with exponential backoff"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if installationID <= 0 || len(repos) != 1 { /* validate inputs before the call */ }","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":"tok, err := app.MintInstallationToken(ctx, id, []string{repo}, nil)\nif err != nil {\n\tswitch {\n\tcase isHTTPStatusErr(err, 401):\n\t\t// refresh App JWT credentials\n\tcase isHTTPStatusErr(err, 403):\n\t\t// installation suspended: surface to operator\n\tcase isHTTPStatusErr(err, 404):\n\t\t// installation removed: re-discover ID\n\tcase isHTTPStatusErr(err, 422):\n\t\t// perms exceed app registration: reduce perms\n\tcase isHTTPStatusErr(err, 500, 502, 503, 504):\n\t\t// transient: retry with backoff\n\t}\n\treturn err\n}","preventionTips":["Verify app permissions registration matches requested perms","Keep the App private key and ID correct; mint JWTs just-in-time","Alert on installation suspension and uninstallation events"],"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"}