MCPcopy
hub / github.com/larksuite/cli / parseIssueCredentialData

Function parseIssueCredentialData

shortcuts/apps/git_credential.go:489–523  ·  view source on GitHub ↗

parseIssueCredentialData turns the git-credential issue response into the credential data map. A standard Lark envelope (top-level "code") and any HTTP error status route through the shared response classifier, so generic codes (missing scope, app not authorized) and 5xx statuses keep their canonica

(resp *larkcore.ApiResp, err error, cc errclass.ClassifyContext)

Source from the content-addressed store, hash-verified

487// non-standard success shapes — direct git info or a BaseResp wrapper — are
488// handled locally.
489func parseIssueCredentialData(resp *larkcore.ApiResp, err error, cc errclass.ClassifyContext) (map[string]any, error) {
490 if err != nil {
491 return nil, redactGitCredentialIssueError(client.WrapDoAPIError(err))
492 }
493 detail := logIDDetail(resp)
494 if resp == nil || len(resp.RawBody) == 0 {
495 return nil, errs.NewInternalError(errs.SubtypeInvalidResponse,
496 "Issue app Git credential: empty response body")
497 }
498 var result map[string]any
499 jsonErr := json.Unmarshal(resp.RawBody, &result)
500 _, hasCode := result["code"]
501 if jsonErr != nil || hasCode || resp.StatusCode >= http.StatusBadRequest {
502 data, cerr := common.ClassifyAPIResponseWith(resp, cc)
503 if cerr != nil {
504 return nil, redactGitCredentialIssueError(withAppsHint(cerr, gitCredentialIssueHint))
505 }
506 if data != nil {
507 result = data
508 }
509 // data == nil: a code==0 envelope whose fields sit beside "code" instead
510 // of under "data" — keep the locally-unmarshalled top-level object.
511 } else if err := checkGitInfoBaseResp(result, logIDString(resp)); err != nil {
512 return nil, err
513 }
514 if detail != nil {
515 if result == nil {
516 result = map[string]any{}
517 }
518 for k, v := range detail {
519 result[k] = v
520 }
521 }
522 return result, nil
523}
524
525func checkGitInfoBaseResp(result map[string]any, logID string) error {
526 for _, key := range []string{"BaseResp", "baseResp", "base_resp"} {

Calls 8

WrapDoAPIErrorFunction · 0.92
NewInternalErrorFunction · 0.92
ClassifyAPIResponseWithFunction · 0.92
logIDDetailFunction · 0.85
withAppsHintFunction · 0.85
checkGitInfoBaseRespFunction · 0.85
logIDStringFunction · 0.85