go-notion
go-notion copied to clipboard
Returns APIError error instead of std err object
Allows the following:
err := notion.Search(...)
notionErr, ok := err.(*APIError)
if ok && notionErr.Code == "rate_limited" {
// retry
}
Please don't forget to create a new release after you merge ;)
The *APIError.Unwrap method and usage of %w in Client should already allow for getting the underlying Notion API error in your own code. For example, see this variation of your code snippet:
import "errors"
err := notion.Search(...)
if errors.Is(err, notion.ErrRateLimited) {
// retry
}
Ref: The errors.Is method and this article for details on sentinel errors, unwrapping, etcetera.
IMO the current implementation of APIError and usage in the Client methods sufficiently allows for handling of errors (either HTTP related or otherwise). Curious to hear your thoughts if you find otherwise.
Closing this after inactivity, pending follow up to my reply.