souvikinator / notion-to-md

Convert notion pages, block and list of blocks to markdown (supports nesting and custom parsing)
https://www.npmjs.com/package/notion-to-md
MIT License
1.08k stars 89 forks source link

Keep errors uncaught #79

Closed esfox closed 1 year ago

esfox commented 1 year ago

Hello! First of all just wanna say thank you for this library. It's very helpful in dealing with getting the content of a Notion page as markdown.

But I believe it is better if error handling would be delegated instead to the user of the library such that we're able to handle the errors ourselves. I understand that returning an empty array would ultimately be fine but I think it's better for the users to be able to handle the errors from the Notion API as they see fit. Some may not even want to have the error logged out.

Code in question below:

https://github.com/souvikinator/notion-to-md/blob/7780938e76c210c1a93332b17ee3b2143fda6a85/src/utils/notion.ts#L31-L34

I myself was surprised that enclosing await n2m.pageToMarkdown(pageId) in a try-catch block did not throw any errors when the pageId I supplied is invalid, hoping that I'll get the error and handle it on my end. But apparently the library was already doing that so I might have no way to catch that error and do my own handling.

If I'm not mistaken, just removing the try-catch block inside getBlockChildren() should be enough since if an error is thrown there, it would escalate all the way up to which function of the library we called.

Would like to know your thoughts on this.

souvikinator commented 1 year ago

Hey thanks for using notion-to-md. That totally makes sense. I'll remove all the try catch block so that users have control over error handling. Should be fixed by the next release.

souvikinator commented 1 year ago

this should be fixed in the upcoming patch v2.7.1

souvikinator commented 1 year ago

live in v3.0.0 Thanks for the contribution.