Tencent/WeKnora · error

unmarshal paginated response: %w

Error message

unmarshal paginated response: %w

What it means

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.

Source

Thrown at internal/datasource/connector/notion/client.go:462

		var respBody []byte
		var err error
		if method == http.MethodPost {
			respBody, err = c.doRequest(ctx, method, path, body)
		} else {
			p := path
			if startCursor != "" {
				p += "?start_cursor=" + startCursor + "&page_size=100"
			}
			respBody, err = c.doRequest(ctx, method, p, nil)
		}
		if err != nil {
			return nil, fmt.Errorf("paginate %s: %w", path, err)
		}

		var resp paginatedResponse
		if err := json.Unmarshal(respBody, &resp); err != nil {
			return nil, fmt.Errorf("unmarshal paginated response: %w", err)
		}

		var pages []notionPage
		if err := json.Unmarshal(resp.Results, &pages); err != nil {
			return nil, fmt.Errorf("unmarshal page results: %w", err)
		}

		for i := range pages {
			pages[i].Title = extractTitle(&pages[i])
		}

		allPages = append(allPages, pages...)

		if !resp.HasMore || resp.NextCursor == "" {
			break
		}
		startCursor = resp.NextCursor
	}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Log the raw respBody (truncated) to see what was actually returned
  2. Check the Notion API version header the client sends matches the expected schema
  3. Verify no proxy/WAF is rewriting responses
  4. Upgrade the connector if Notion changed the response schema
Defensive patterns

Strategy: try-catch

Validate before calling

ct := resp.Header.Get("Content-Type"); if !strings.Contains(ct, "application/json") { return errors.New("non-JSON response") }

Try / catch

if err != nil && strings.Contains(err.Error(), "unmarshal paginated response") {
    // log raw body (truncated) and surface as infrastructure error
    return fmt.Errorf("notion returned unexpected response: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: Corporate proxy or captive portal intercepting the response, Notion API version mismatch changing the response shape, truncated response bodies.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/8b79669a7ed65ac6. Report an issue: GitHub.