gastownhall/beads · error

parse current user response: %w

Error message

parse current user response: %w

What it means

GetCurrentUser calls the Notion /users/me endpoint and unmarshals the JSON body into a User. If the response body isn't valid JSON or doesn't match the User shape, the json error is wrapped with this message.

Source

Thrown at internal/notion/client.go:59

	clone := *c
	clone.HTTPClient = httpClient
	return &clone
}

func (c *Client) WithBaseURL(baseURL string) *Client {
	clone := *c
	clone.BaseURL = strings.TrimSuffix(baseURL, "/")
	return &clone
}

func (c *Client) GetCurrentUser(ctx context.Context) (*User, error) {
	body, err := c.doRequest(ctx, http.MethodGet, "/users/me", nil)
	if err != nil {
		return nil, err
	}
	var user User
	if err := json.Unmarshal(body, &user); err != nil {
		return nil, fmt.Errorf("parse current user response: %w", err)
	}
	return &user, nil
}

func (c *Client) RetrieveDataSource(ctx context.Context, dataSourceID string) (*DataSource, error) {
	body, err := c.doRequest(ctx, http.MethodGet, "/data_sources/"+url.PathEscape(dataSourceID), nil)
	if err != nil {
		return nil, err
	}
	var ds DataSource
	if err := json.Unmarshal(body, &ds); err != nil {
		return nil, fmt.Errorf("parse data source response: %w", err)
	}
	return &ds, nil
}

func (c *Client) RetrieveDatabase(ctx context.Context, databaseID string) (*Database, error) {
	body, err := c.doRequest(ctx, http.MethodGet, "/databases/"+url.PathEscape(databaseID), nil)

View on GitHub (pinned to 71377f2769)

Solutions

  1. Print/log the raw response body to see what was actually returned.
  2. Verify the client's base URL and that no proxy intercepts requests to api.notion.com.
  3. Check the notion library version against the current Notion API and update the User struct if the schema changed.
Defensive patterns

Strategy: type-guard

Type guard

func isNotionParseError(err error) bool {
    return err != nil && strings.Contains(err.Error(), "parse current user response")
}

Try / catch

user, err := client.GetCurrentUser(ctx)
if err != nil {
    var jsonErr *json.UnmarshalTypeError
    if errors.As(err, &jsonErr) {
        return fmt.Errorf("unexpected Notion response, check API version: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: json.Unmarshal(body, &user) fails after a successful doRequest: malformed JSON, HTML error page returned with 200, or unexpected field types.

Common situations: Proxy/captive portal returning HTML; wrong base URL pointing at a non-Notion service; Notion API change; truncated response.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/6057b1c35e75d845. Report an issue: GitHub.