{"record":{"id":"37ae93e649a28c0c","repo":"larksuite/cli","slug":"failed-to-parse-response-w-37ae93","errorCode":null,"errorMessage":"failed to parse response: %w","messagePattern":"failed to parse response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/verify.go","lineNumber":34,"sourceCode":"// VerifyUserToken calls /authen/v1/user_info to confirm the token is accepted server-side.\n// Returns nil on success or an error describing why the server rejected the token.\nfunc VerifyUserToken(ctx context.Context, sdk *lark.Client, accessToken string) error {\n\tapiResp, err := sdk.Do(ctx, &larkcore.ApiReq{\n\t\tHttpMethod:                http.MethodGet,\n\t\tApiPath:                   PathUserInfoV1,\n\t\tSupportedAccessTokenTypes: []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser},\n\t}, larkcore.WithUserAccessToken(accessToken))\n\tif err != nil {\n\t\treturn err\n\t}\n\tlogSDKResponse(PathUserInfoV1, apiResp)\n\n\tvar resp struct {\n\t\tCode int    `json:\"code\"`\n\t\tMsg  string `json:\"msg\"`\n\t}\n\tif err := json.Unmarshal(apiResp.RawBody, &resp); err != nil {\n\t\treturn fmt.Errorf(\"failed to parse response: %w\", err)\n\t}\n\tif resp.Code != 0 {\n\t\treturn fmt.Errorf(\"[%d] %s\", resp.Code, resp.Msg)\n\t}\n\treturn nil\n}\n","sourceCodeStart":16,"sourceCodeEnd":41,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/auth/verify.go#L16-L41","documentation":"VerifyUserToken successfully called the token-verification API, but json.Unmarshal on apiResp.RawBody failed, so the verification verdict could not be determined. The %w wrap preserves the unmarshal error (syntax error, type mismatch).","triggerScenarios":"json.Unmarshal(apiResp.RawBody, &resp) fails in VerifyUserToken — the verification endpoint returned a non-JSON body (HTML error page, empty body) or a body whose shapes don't match {code:int, msg:string}.","commonSituations":"Gateway outage returning HTML; wrong endpoint/base URL; a version change where the verify endpoint returns a differently-shaped JSON (e.g. string code); truncated response on flaky networks.","solutions":["Dump apiResp.RawBody to see what was actually returned; an HTML page means the request never hit the API — check base URL/proxy.","Check the HTTP status of apiResp; a 5xx with plain text body points at a gateway problem, retry later.","Confirm the code and endpoint match the current Feishu API version (field shapes may change).","If RawBody is empty, verify the API call path that produced apiResp."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// before verifying, sanity-check that the raw body looks like JSON\nif len(apiResp.RawBody) == 0 || apiResp.RawBody[0] != '{' {\n    return fmt.Errorf(\"verify endpoint returned non-JSON (HTTP %d): %.200q\", apiResp.StatusCode, apiResp.RawBody)\n}","typeGuard":"func isParseErr(err error) bool {\n    var syn *json.SyntaxError\n    var typ *json.UnmarshalTypeError\n    return errors.As(err, &syn) || errors.As(err, &typ)\n}","tryCatchPattern":"if err := auth.VerifyUserToken(ctx, token); err != nil {\n    if isParseErr(err) {\n        return fmt.Errorf(\"verify response shape changed or gateway returned HTML; check base URL/API version: %w\", err)\n    }\n    return err\n}","preventionTips":["Assert the verify endpoint URL matches the current Feishu API version.","Pin/verify the expected response shape {code:int,msg:string} in tests.","Log RawBody and status on parse failure for fast diagnosis.","Guard against gateways returning HTML by checking content-type before unmarshal."],"tags":["json","parse-error","auth","token-verification"],"backgroundTag":"non-json-response","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}