mirror of
https://github.com/dstotijn/go-notion.git
synced 2025-07-03 00:46:49 +02:00
Don't panic when unmarshaling blocks (#50)
* don't panic * Block() returns err * Rework unknown block type logic, add tests --------- Co-authored-by: David Stotijn <dstotijn@gmail.com>
This commit is contained in:
@ -437,7 +437,7 @@ func (c *Client) FindBlockByID(ctx context.Context, blockID string) (Block, erro
|
||||
return nil, fmt.Errorf("notion: failed to parse HTTP response: %w", err)
|
||||
}
|
||||
|
||||
return dto.Block(), nil
|
||||
return dto.Block()
|
||||
}
|
||||
|
||||
// UpdateBlock updates a block.
|
||||
@ -472,10 +472,11 @@ func (c *Client) UpdateBlock(ctx context.Context, blockID string, block Block) (
|
||||
return nil, fmt.Errorf("notion: failed to parse HTTP response: %w", err)
|
||||
}
|
||||
|
||||
return dto.Block(), nil
|
||||
return dto.Block()
|
||||
}
|
||||
|
||||
// DeleteBlock sets `archived: true` on a (page) block object.
|
||||
// Will return UnsupportedBlockError if it deletes the block but cannot decode it
|
||||
// See: https://developers.notion.com/reference/delete-a-block
|
||||
func (c *Client) DeleteBlock(ctx context.Context, blockID string) (Block, error) {
|
||||
req, err := c.newRequest(ctx, http.MethodDelete, "/blocks/"+blockID, nil)
|
||||
@ -500,7 +501,7 @@ func (c *Client) DeleteBlock(ctx context.Context, blockID string) (Block, error)
|
||||
return nil, fmt.Errorf("notion: failed to parse HTTP response: %w", err)
|
||||
}
|
||||
|
||||
return dto.Block(), nil
|
||||
return dto.Block()
|
||||
}
|
||||
|
||||
// FindUserByID fetches a user by ID.
|
||||
|
Reference in New Issue
Block a user