I have a processing cloud page and the page redirects correctly to success page but when I add in extra bit of code for error page redirect, records evaluating success still goes to the error page. Am I missing something here?

Thank you in advance.

try {
   var token = getToken(setup);
   var success = false
   if (!!token) success = triggerEvent(token setup, data);
   if (!!success) {
      Redirect("https://successpage.com", true);}
   else {
      Redirect("https://errorpage.com", true);}
} catch (e) {
  • What are your getToken() and triggerEvent() returning? Could they be returning undefined or raising an error leading you to always ending up at the error page?
    – Macca
    Commented Jul 24, 2020 at 5:47
  • If I remove the error page redirect, and replace with write, it works fine. When it is success, it will redirect to success page and error is displayed on the page. Problem is only when I add the 2 error page redirects.
    – s3002068
    Commented Jul 24, 2020 at 5:51
  • Can you try flipping the second param of your Redirects from "true" to "false" and clear your cache/bypass the cache in developer tools? You're setting a permanent redirection (301) that would be cached by your browser.
    – Macca
    Commented Jul 24, 2020 at 6:10
  • hey @Macca, doesn't seem to work. Still sends to error page. :(
    – s3002068
    Commented Jul 24, 2020 at 6:37
  • 1
    Redirect function inside try throws an error - reffer to this respons by Gortonington - salesforce.stackexchange.com/questions/311799/… Commented Jul 24, 2020 at 12:07

1 Answer 1


This is an issue around that all redirect functions will throw an exception due to the 'breaking' from the script. There are a couple ways to get around this, please see this SFSE post that recently experienced the same issue or check out a post I made on HowToSFMC.com about this as well as other potential pitfalls with Try/Catch.

Basic synopsis of the issue:

It appears this is a well documented .Net issue revolving around that Redirects will throw a ‘ThreadAbort’ exception, which would trigger the catch block to run instead. Now SFMC SSJS does not have all the great exception handling capabilities that you can see in languages like .Net.

and my recommended solution:

<script runat="server">
    var redirect = 'https://google.com'

    } catch(e) {
        var desc = e.description; //Pulls the description from error object
        if(desc.indexOf("ExactTarget.OMM.AMPScriptRedirectException") > -1) {
          Platform.Response.Write(desc) //This is arbitrary as will not be run
        } else {
          redirect = 'https://yahoo.com'

By throwing the redirect into an if statement, you remove it from being processed if the exception thrown is just from the redirect, it will instead only be processed for other exceptions.

  • This worked! Thanks so much!
    – s3002068
    Commented Jul 27, 2020 at 9:45

You must log in to answer this question.

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