Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw typed exceptions #6

Open
filipetoscano opened this issue Oct 30, 2024 · 3 comments
Open

Throw typed exceptions #6

filipetoscano opened this issue Oct 30, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@filipetoscano
Copy link
Collaborator

filipetoscano commented Oct 30, 2024

Current:

  • Exceptions are thrown by call to EnsureSuccessStatusCode

After:

@filipetoscano filipetoscano added the enhancement New feature or request label Oct 30, 2024
@christina-de-martinez
Copy link

It looks like this was taken care of already, e.g.: #7 -- is there more to do here?

@filipetoscano
Copy link
Collaborator Author

filipetoscano commented Jan 19, 2025

The SDK currently throws ResendException exclusively. The idea was to throw derived exceptions (e.g. ResendRateLimitExceededException) so that calling code could trap specific exceptions as necessary.

However, a similar effect can also be accomplished with the when clause:

try
{
   await _resend.EmailSendAsync( ... );
}
catch ( ResendException ex ) when ( ex.ErrorType == ErrorType.RateLimitExceeded )
{
    Console.Error.WriteLine( "Rate limit exceeded: please wait before retrying" );
}
catch ( ResendException ex )
{
    Console.Error.WriteLine( "err: {0} - {1}", ex.ErrorType, ex.Message );
}

Having said that, a specialized ResendRateLimitExceededException could include ResendRateLimit as a property, so that the calling code can check how long it should wait before the next retry.

Console.Error.WriteLine( "Rate limit exceeded: please wait {0}s before retrying", ex.Limits?.RetryAfter );

@christina-de-martinez
Copy link

Thanks for the explanation, @filipetoscano

I took a shot at adding ResendRateLimitExceededException and using it once. I wanted to check if I'm on the right track before adding more. PR: #18

I also added an option to auto retry, since we know how long the client needs to wait before retrying. This can be disabled if users don't want this functionality.

I'm learning C# and using this as a way to practice, so if this is way off, you can just ignore me. But if it's close enough to be helpful I'd appreciate your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants