{"record":{"id":"960e1ab8c5acfd6b","repo":"Tencent/WeKnora","slug":"unmarshal-page-w","errorCode":null,"errorMessage":"unmarshal page: %w","messagePattern":"unmarshal page: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/datasource/connector/notion/client.go","lineNumber":174,"sourceCode":"\t_, err := c.doRequest(ctx, http.MethodGet, \"/v1/users/me\", nil)\n\treturn err\n}\n\n// SearchPages returns all pages and databases accessible to the integration.\nfunc (c *notionClient) SearchPages(ctx context.Context) ([]notionPage, error) {\n\treturn c.paginatePages(ctx, http.MethodPost, \"/v1/search\")\n}\n\n// GetPage retrieves a single page by ID.\nfunc (c *notionClient) GetPage(ctx context.Context, pageID string) (*notionPage, error) {\n\trespBody, err := c.doRequest(ctx, http.MethodGet, \"/v1/pages/\"+pageID, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar page notionPage\n\tif err := json.Unmarshal(respBody, &page); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal page: %w\", err)\n\t}\n\tpage.Title = extractTitle(&page)\n\treturn &page, nil\n}\n\n// databaseInfo holds both the metadata and the data source ID from a single API call.\ntype databaseInfo struct {\n\tPage         notionPage\n\tDataSourceID string\n}\n\n// GetDatabaseInfo retrieves a database container by ID, returning both\n// the page metadata and the primary data source ID in a single API call.\nfunc (c *notionClient) GetDatabaseInfo(ctx context.Context, dbID string) (*databaseInfo, error) {\n\trespBody, err := c.doRequest(ctx, http.MethodGet, \"/v1/databases/\"+dbID, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/datasource/connector/notion/client.go#L156-L192","documentation":"GetPage fetched a page successfully from /v1/pages/{id} but json.Unmarshal of the response into the notionPage struct failed. This indicates the response body is not valid JSON or its shape doesn't match notionPage's typed fields. The doRequest call itself succeeded, so auth and network were fine.","triggerScenarios":"GET /v1/pages/{pageID} returns a body that fails to decode into notionPage — e.g. an HTML error page from a proxy (2xx but not JSON), or a Notion response whose typed fields (created_time, last_edited_time, etc.) change shape in a new API version while Notion-Version header pins an older version.","commonSituations":"A reverse proxy or captive portal returning 200 with HTML instead of JSON; Notion API version drift changing response schemas; corrupted gzip/encoding handling by an intermediary; baseURL accidentally pointing at a non-Notion service that answers 200 with other content.","solutions":["Print/log the raw respBody on failure to see what was actually returned — usually reveals HTML or unexpected JSON.","Verify baseURL is https://api.notion.com (or a faithful proxy) and not intercepting with 200 responses.","Pin NotionAPIVersion to a version compatible with the notionPage struct; update struct tags if you upgrade the API version.","Check that no proxy injects content (disable HTTPS interception or trust the proxy's CA properly)."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isLikelyJSON(b []byte) bool {\n    t := bytes.TrimSpace(b)\n    return len(t) > 0 && (t[0] == '{' || t[0] == '[')\n}\n// usage: if !isLikelyJSON(respBody) { /* proxy/HTML interference */ }","tryCatchPattern":"page, err := client.GetPage(ctx, pageID)\nif err != nil && strings.HasPrefix(err.Error(), \"unmarshal page:\") {\n    // log raw response via tracing middleware; suspect proxy or schema drift\n    log.Printf(\"non-conforming page response: %v\", err)\n}","preventionTips":["Use the official baseURL (https://api.notion.com/v1) — avoid 200-response interceptors","Pin NotionAPIVersion and test struct compatibility after version upgrades","Add a debug mode that logs raw bodies on unmarshal failure","Keep notionPage struct tags updated when fields are added to the client"],"tags":["notion","json","unmarshal","schema","api"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}