{"record":{"id":"8b79669a7ed65ac6","repo":"Tencent/WeKnora","slug":"unmarshal-paginated-response-w","errorCode":null,"errorMessage":"unmarshal paginated response: %w","messagePattern":"unmarshal paginated response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/datasource/connector/notion/client.go","lineNumber":462,"sourceCode":"\n\t\tvar respBody []byte\n\t\tvar err error\n\t\tif method == http.MethodPost {\n\t\t\trespBody, err = c.doRequest(ctx, method, path, body)\n\t\t} else {\n\t\t\tp := path\n\t\t\tif startCursor != \"\" {\n\t\t\t\tp += \"?start_cursor=\" + startCursor + \"&page_size=100\"\n\t\t\t}\n\t\t\trespBody, err = c.doRequest(ctx, method, p, nil)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"paginate %s: %w\", path, err)\n\t\t}\n\n\t\tvar resp paginatedResponse\n\t\tif err := json.Unmarshal(respBody, &resp); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unmarshal paginated response: %w\", err)\n\t\t}\n\n\t\tvar pages []notionPage\n\t\tif err := json.Unmarshal(resp.Results, &pages); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unmarshal page results: %w\", err)\n\t\t}\n\n\t\tfor i := range pages {\n\t\t\tpages[i].Title = extractTitle(&pages[i])\n\t\t}\n\n\t\tallPages = append(allPages, pages...)\n\n\t\tif !resp.HasMore || resp.NextCursor == \"\" {\n\t\t\tbreak\n\t\t}\n\t\tstartCursor = resp.NextCursor\n\t}","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/datasource/connector/notion/client.go#L444-L480","documentation":"After a successful HTTP call, paginatePages unmarshals the raw JSON body into paginatedResponse. If Notion's response is not the expected envelope (object with results/next_cursor/has_more), json.Unmarshal fails and the error is wrapped with this message.","triggerScenarios":"The endpoint returns valid HTTP 200 but a body that doesn't decode into paginatedResponse — e.g. an HTML error page, a proxy/gateway message, or a Notion error object served with 200.","commonSituations":"Corporate proxy or captive portal intercepting the response, Notion API version mismatch changing the response shape, truncated response bodies.","solutions":["Log the raw respBody (truncated) to see what was actually returned","Check the Notion API version header the client sends matches the expected schema","Verify no proxy/WAF is rewriting responses","Upgrade the connector if Notion changed the response schema"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"ct := resp.Header.Get(\"Content-Type\"); if !strings.Contains(ct, \"application/json\") { return errors.New(\"non-JSON response\") }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unmarshal paginated response\") {\n    // log raw body (truncated) and surface as infrastructure error\n    return fmt.Errorf(\"notion returned unexpected response: %w\", err)\n}","preventionTips":["Ensure no proxy/WAF intercepts api.notion.com traffic","Log truncated raw bodies on decode failures to diagnose schema drift","Keep the connector updated for Notion API changes"],"tags":["notion","json","unmarshal","pagination"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}