Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad Request Check `Errors` for a list of errors returned by the API. at SendGrid

I'm using send grid to send an email after a user is created and I'm following This tutorial Here http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity I even downloaded This tutorial and wrote code as it is

but it code breaks at this

string code = manager.GenerateEmailConfirmationToken(uApp.Id);
string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, uApp.Id, Request);
 manager.SendEmail(uApp.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

Its This third like

manager.SendEmail(uApp.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

Where code breaks

and the errors is like this

Exceptions.InvalidApiRequestException: Bad Request Check Errors for a list of errors returned by the API. at SendGrid.Web.d__c.MoveNext() -- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at SendGrid.Web.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at GCRweb.EmailService.d__0.MoveNext()

and bla bla bla before this it was giving me an error on first line abot some token and stuff What is that I'm doing wrong

like image 716
Dare Devs Avatar asked Dec 14 '22 16:12

Dare Devs


1 Answers

InvalidApiRequestException exception is the key.

The best way to handle errors using DeliverAsync() method is something like this:

            try
            {
                await transportWeb.DeliverAsync(mensaje);
            }
            catch (InvalidApiRequestException ex)
            {
                var detalle = new StringBuilder();

                detalle.Append("ResponseStatusCode: " + ex.ResponseStatusCode + ".   ");
                for (int i = 0; i < ex.Errors.Count(); i++)
                {
                    detalle.Append(" -- Error #" + i.ToString() + " : " + ex.Errors[i]);
                }

                throw new ApplicationException(detalle.ToString(), ex);
            }
like image 173
RolandoCC Avatar answered Apr 28 '23 12:04

RolandoCC