0

I developed a webhook receiver to read custom values sent in the mail and save that values in the database. When I tested this on the postman, it is saving values in the database. but when I tested this in hasura, it shows an error like ' an error has occurred '. I am unable to figure out what I am missing. Following is my code.

GenericWebhook.cs

public class GenericWebhook: WebHookHandler

{
    public GenericWebhook()
    {
        this.Receiver = "genericjson";
    }

    public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
    {
        try
        {
           // context = "";

            JObject data = context.GetDataOrDefault<JObject>();
           dynamic response = JsonConvert.DeserializeObject(data.ToString());

                List<ReturnResultBL> ResultList = response.Payload.ToObject<List<ReturnResultBL>>();

                WebhookLocal webhookObj = new WebhookLocal();

                string varResult = webhookObj.SaveMailDetails(ResultList);

           return Task.FromResult(false);
        }
        catch (Exception ex)
        {
            throw;
        }

    }

WebhookLocal.cs ----

public class WebhookLocal
{
    internal string SaveMailDetails(List<ReturnResultBL> resultList)
    {
        try
        {
 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TPAConnection"].ConnectionString);
            con.Open();

            string query = "insert into tblMailData(col1,col2,..)values('col1','col2');
 SqlCommand cmd = new SqlCommand(query, con);
 int rVal = cmd.ExecuteNonQuery();
            con.Close();
 }
        catch (Exception ex)
        {
          throw;
        }

        return "true";


    }
  • Are you able to debug the code when testing from hasura? You are just throwing the exception, not handling them. You should handle the exception and log them in to some log file so that you can read the log file and figure out what is the exception what could have caused it. – Chetan Apr 25 '19 at 12:47
  • @ChetanRanpariya I am not able to debug from hasura. Thanks for the advice about writing log. – Sarita Patil Apr 26 '19 at 04:53
  • I have written the logs. Error caught in the log file is as follows.---------------------Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at WebhookReceiver1._0.Controllers.GenericWebhook.ExecuteAsync(String receiver, WebHookHandlerContext context) in D:\Projects\WebhookReceiver2.0\WebhookReceiver1.0\WebhookReceiver1.0\Controllers\GenericWebhook.cs:line 58. – Sarita Patil Apr 29 '19 at 08:44
  • The path location "D:\Projects\WebhookReceiver2.0\Controllers\GenericWebhook.cs:line 58" is my local location. And error caught at the server location. – Sarita Patil Apr 29 '19 at 08:48
  • What code is written at `GenericWebhook.cs:line 58`? – Chetan Apr 29 '19 at 09:29
  • @ChetanRanpariya This code is at line 58 List ResultList = response.Payload.ToObject>(); – Sarita Patil Apr 29 '19 at 09:35
  • Solved this error. Thank you for replies. – Sarita Patil May 13 '19 at 06:55

0 Answers0