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)
| 487 | // non-standard success shapes — direct git info or a BaseResp wrapper — are |
| 488 | // handled locally. |
| 489 | func 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 | |
| 525 | func checkGitInfoBaseResp(result map[string]any, logID string) error { |
| 526 | for _, key := range []string{"BaseResp", "baseResp", "base_resp"} { |