go-notion icon indicating copy to clipboard operation
go-notion copied to clipboard

Returns APIError error instead of std err object

Open samber opened this issue 2 years ago • 1 comments

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 ;)

samber avatar Aug 17 '22 21:08 samber

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.

dstotijn avatar Aug 18 '22 07:08 dstotijn

Closing this after inactivity, pending follow up to my reply.

dstotijn avatar Oct 27 '22 09:10 dstotijn