2

I have an email calling a service to get information through HTTPGet. IF that service fails to provide an answer, I want to log the failure and I don't want to send the email so I have created and InsertDE statement to log the error (which I have verified) and I added the RaiseError() function. As I read the documentation at RaiseError and have seen this post: How to use all the parameters of the RaiseError function?

I should be able to do what I want by setting the 5th parameter to "1" as in my code:

 ELSE
    SET @errorMsg = CONCAT("Failed to Parse Service Response: ",@couponInfo)
    INSERTDE("CouponCodeErrorLog","Date",Now(),"EmailName",@couponName, "EmailAddress",emailaddr,"SubscriberKey",_subscriberkey,"Error",@errorMsg)
    SET @expiry = "failed to load" 
    RaiseError("Do not send to subscriber", true,"errorcode","1234",1) 
 ENDIF

but the InsertDE function only works when the RaiseError() function is commented out. Does anyone know what I am doing wrong here?

2 Answers 2

3

Your problem is likely your error has already occurred in the HttpGet, so your script never gets to the ELSE statement.

It's not a particularly great idea to mix and match AMPScript and SSJS in emails for a couple of reasons - Support treat you like a lepar with any cases relating to the email and, secondly, performance for large sends is really poor. That said...

SSJS does allow you to handle your errors more gracefully and sometimes there isn't much of an option. Here's an example of handing errors from a HttpGet.

<script runat=server>
  Platform.Load("Core","1");
  try {
    </script>
    %%[
        SET @fetched = HTTPGET("http://someurlthatwillfail")
    ]%%
    <script runat=server>
  }
  catch (err)
  {
    </script>
    %%[
        /* Log Data Here */
    ]%%
    <script runat=server>
  }
</script>

The other thing I'd seriously ask you to consider is caching this HttpGet with TreatAsContentArea or "before;httpget;" if each of these subscribers is essentially asking for the same information from the URL you're hitting. HttpGets are really, really, really expensive in terms of send speed.

2
  • 1
    Thanks for your thoughts. In this case I am getting text back as "couponcode|expirationdate" which I split on the pipe &use as parameters in the coupon. (And yes I do know about the claimrow function). This part works fine. Also, I know it is the RaiseError() function which stops the processing because when I comment out RaiseError(), the code does log the error in my DE and send goes through. SFMC documentation says RaiseError will rollback InsertDE unless you specify the true (1) value for the 5th parameter, then it should allow this function to continue. Support is currently baffled too. Jun 9, 2017 at 17:30
  • Thanks for the clarification. My point was that, if your HttpGet does not return a 200 range HTTP response, AMP will error and you'll never get to your ELSE block above. When "service fails to provide an answer", what happens here? The page returns 200 or other response?
    – Macca
    Jun 10, 2017 at 1:15
0

I was having this same issue and in classic Marketing Cloud fashion, the solution seems to be something that makes no sense. You have to SET whatever Data Extension function you want to persist even if the RaiseError is triggered.

So, instead of...

INSERTDE("CouponCodeErrorLog","Date",Now(),"EmailName",@couponName, "EmailAddress",emailaddr,"SubscriberKey",_subscriberkey,"Error",@errorMsg)

Use...

SET @InsertSomething = INSERTDE("CouponCodeErrorLog","Date",Now(),"EmailName",@couponName, "EmailAddress",emailaddr,"SubscriberKey",_subscriberkey,"Error",@errorMsg)

...and the data will be retained, even when the RaiseError cancels the send.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .