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 an exception if a template ID does not exist in your request body #760

Open
thinkingserious opened this issue Oct 6, 2018 · 5 comments
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@thinkingserious
Copy link
Contributor

Issue Summary

You will not receive an error from the API is you send an email with the wrong template. Instead you will get a "Not Delivered" notice in your email activity feed. We want to make that experience better by throwing an exception in the code instead.

This issue is inspired by this.

Acceptance Criteria

  • Use the API to verfiy a template ID exists, if not, throw an exception
  • A new test is added that demonstrates that if you use a non-existent template, the code will throw an error
@thinkingserious thinkingserious added difficulty: medium fix is medium in difficulty hacktoberfest status: help wanted requesting help from the community type: twilio enhancement feature request on Twilio's roadmap labels Oct 6, 2018
@Jerrgree
Copy link

Jerrgree commented Oct 6, 2018

I'll work on this

@Jerrgree Jerrgree mentioned this issue Oct 6, 2018
6 tasks
@devchas devchas added status: work in progress Twilio or the community is in the process of implementing and removed help wanted status: help wanted requesting help from the community labels Oct 11, 2018
@childish-sambino childish-sambino added status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap and removed hacktoberfest status: work in progress Twilio or the community is in the process of implementing type: twilio enhancement feature request on Twilio's roadmap labels Jul 16, 2020
@Hantsch
Copy link

Hantsch commented Oct 16, 2020

Any progress so far? Would also need an endpoint like that.

@childish-sambino
Copy link
Contributor

@Hantsch Not yet. Pull requests and +1s on the issue summary will help it move up the backlog.

@bossbast1
Copy link

@Hantsch Not yet. Pull requests and +1s on the issue summary will help it move up the backlog.

Hey there, still no plans to this in near future?

@Jericho
Copy link

Jericho commented Aug 3, 2021

If you are willing to use the StrongGrid C# library instead of SendGrid's own library, you could very easily validate if a given template exists before attempting to send an email. Your code would look something like this:

// Validate the templateId
var templateIsValid = false;
try
{
    var template = await client.Templates.GetAsync(templateId, null, cancellationToken).ConfigureAwait(false);
    templateIsValid = true;
}
catch (SendGridException e) when (e.StatusCode == System.Net.HttpStatusCode.NotFound)
{
    // In this context we can safely ignore 'NotFound' exceptions because
    // it simply means that the 'templateId' is not valid.
    templateIsValid = false;
}

if (templateIsValid)
{
    // Send email using a dynamic template
    await client.Mail.SendToSingleRecipientAsync(to, from, templateId, cancellationToken: cancellationToken).ConfigureAwait(false);
}
else
{
    // Fallback to sending email without a template
    await client.Mail.SendToSingleRecipientAsync(to, from, subject, html, text, cancellationToken: cancellationToken).ConfigureAwait(false);
}

Hopefully this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

7 participants