v201603 + C# + ClearScript + JScript = error handling issue

51 views
Skip to first unread message

axtens

unread,
May 16, 2016, 3:35:02 AM5/16/16
to AdWords API Forum
I've already asked this question up on StackOverflow, but I'll try to summarise and amplify given the 3 or so hours since posting.

In my madness I've wrapped the AdWords API in a bit of C# that uses ClearScript to expose API types to JScript using code like this:

    JSengine.AddHostType("AdWordsAppConfig", typeof(AdWordsAppConfig));
    JSengine.AddHostType("AdWordsService", typeof(AdWordsService));
    JSengine.AddHostType("AdWordsUser", typeof(AdWordsUser));
    JSengine.AddHostType("ApiError", typeof(ApiError));
    JSengine.AddHostType("BillingAccount", typeof(BillingAccount));
    JSengine.AddHostType("Budget", typeof(Budget));
    JSengine.AddHostType("BudgetBudgetDeliveryMethod", typeof(BudgetBudgetDeliveryMethod));
    JSengine.AddHostType("BudgetBudgetStatus", typeof(BudgetBudgetStatus));
    JSengine.AddHostType("BudgetOperation", typeof(BudgetOperation));
    JSengine.AddHostType("BudgetOrder", typeof(BudgetOrder));
    JSengine.AddHostType("BudgetOrderOperation", typeof(BudgetOrderOperation));
    JSengine.AddHostType("BudgetOrderPage", typeof(BudgetOrderPage));
    JSengine.AddHostType("BudgetOrderRequest", typeof(BudgetOrderRequest));
    JSengine.AddHostType("BudgetOrderReturnValue", typeof(BudgetOrderReturnValue));
    JSengine.AddHostType("BudgetOrderService", typeof(BudgetOrderService));
    JSengine.AddHostType("BudgetPage", typeof(BudgetPage));
    JSengine.AddHostType("BudgetReturnValue", typeof(BudgetReturnValue));
    JSengine.AddHostType("DateRange", typeof(DateRange));
    JSengine.AddHostType("Money", typeof(Money));
    JSengine.AddHostType("Operator", typeof(Operator));
    JSengine.AddHostType("OrderBy", typeof(OrderBy));
    JSengine.AddHostType("Paging", typeof(Paging));
    JSengine.AddHostType("Predicate", typeof(Predicate));
    JSengine.AddHostType("PredicateOperator", typeof(PredicateOperator));
    JSengine.AddHostType("Selector", typeof(Selector));
    JSengine.AddHostType("SortOrder", typeof(SortOrder));
            
So far so good. I've got gets and mutates working. But I have a bit of a problem with what happens when an error occurs.

In the JScript script (yeah, Microsoft's server-side JavaScript) I have (in part)

    var order = new BudgetOrder();
    order.billingAccountId = acct.id;
    order.startDateTime = "20160830 000000 Australia/Perth";
    order.endDateTime = "20160830 235959 Australia/Perth";
    var amt = new Money();
    amt.microAmount = 10000000;
    order.spendingLimit = amt;

    var boo = new BudgetOrderOperation();
    boo.operator = Operator.ADD;
    boo.operand = order;
    var mutations = ToTypedArray(BudgetOrderOperation, [boo]);

    var response;    
    try {
      response = bos.mutate(mutations);
      Console.WriteLine(response.value[0].billingAccountId);
      Console.WriteLine(response.value[0].id);
      Console.WriteLine(response.value[0].lastRequest.status.ToString());
    } catch (exc) {
      Console.WriteLine(exc.message);
    }

If the mutate fails for whatever reason, in the last case due to an INVALID_BUDGET_DATE_RANGE, the catch fires. Fine. However the exc var contains very little useful information apart from

    description: "" 
    message: "" 
    name: "Error" 
    number: -2146190593 

Is there a callback or some global data structure I can hook into that will let me know what the result of the transaction attempt was? Are there any alternatives I should think about?
Reply all
Reply to author
Forward
0 new messages