1
0
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:
bassettb
2023-02-21 14:28:33 -05:00
committed by GitHub
parent 87a7d4c3cd
commit c6f2e5b343
3 changed files with 118 additions and 39 deletions

View File

@ -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.