resend / resend-go

Resend's Official Go SDK
https://resend.com
MIT License
98 stars 9 forks source link

Need better way of parsing/catching specific errors? #41

Open benguild opened 2 months ago

benguild commented 2 months ago

It seems like the only way to catch stuff like this is with string comparison:

if err != nil && strings.HasPrefix(err.Error(), "[ERROR]: Invalid `to` field.") {
    // cancel, etc.
}

… Am I missing something here? If not, it feels a bit delicate.

For example, if the API rejects a bad email address, we want to be able to catch that specific error.

drish commented 2 months ago

hi @benguild, that's a good point, currently the SDK doesn't provide a way to catch specific errors, so you end up having to using something like HasPrefix. I have recently started working back again on adding all error types for all categories, see here, these errors should e caught by errors.Is, you can expect a release that covers this sometime in the next coming weeks.