Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Redirect 500 internal server error inside try catch SSJS block

SFMC tips and tricks

If you have Redirect function inside the try catch block, either as mixture of SSJS with AMPScript or only in SSJS, it will throw an 500 – Internal Server Error.

Let’s take a look on few examples what can create an error that will take you some quality debugging time to figure it out. And frankly to debug something inside the marketing cloud is one of the most depressing things happened to me in a while.

<script runat=server>
try{
  //do somothing
  throw 'This is error'
}catch(e){
	Redirect('https://example.com',true)
}

</script>
<script runat=server>
 try{
 </script>
  %%[
   /* Do some AMPScript */
   /* e.g. */
 	UpdateSingleSalesforceObject('Contact', 'contactId', 'someField', 'True')
    Redirect(CloudPagesURL(1))
 ]%% 
 <script runat=server>
 }catch(e){
  //do something
 }
</script>

Examples above will throw beautiful 500 – Internal Server Error and leave you guessing what is wrong this time.

To make this work you have to move any redirect functions outside the try-catch block.

<script runat=server>
 var error = false
try{
  //do somothing
  throw 'This is error'
}catch(e){
  	/* you can log e.message into  Data Extension */
	error = true
}
Redirect('https://example.com', true)
</script>

Oh hi there đź‘‹
I have a FREE e-book for you.

Sign up now to get an in-depth analysis of Adobe and Salesforce Marketing Clouds!

We don’t spam! Read our privacy policy for more info.

Marcel Szimonisz
Marcel Szimonisz
MarTech consultant As a marketing automation consultant, I specialize in solving problems, automating processes, and driving innovation in my clients' marketing platforms.

I hold certifications in Adobe Campaign v6 (3x certified) and Salesforce Marketing Cloud (5x certified).

Additionally, I serve as a community advisor for Adobe Campaign, offering expert insights and guidance.

In addition to my professional pursuits, I also enjoy exploring various programming languages, CMSs, and frameworks, further enhancing my technical expertise and staying at the forefront of industry advancements.
Take a look at our subscription offering in case you are looking for a Marketing Automation Consultant.

Leave a comment

Your email address will not be published. Required fields are marked *

Similar posts that you may find useful

SFMC tips and tricks
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Error updating filter and new data extension

less than a minute read

If you’re using Email Studio in Salesforce Marketing Cloud and receive an ‘Error: updating filter’ message when creating a new Data Extension, it’s likely because the name you’ve chosen already exists. This error message can be misleading, but a simple solution is to rename the Data Extension with a more unique identifier. Make sure to […]

Continue reading
SFMC tips and tricks
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

SFMC TIP – Double quotes in AMPScript break email template

less than a minute read

Very recently I have found that when I add any AMPScript function to eg. button URL field SFMC will just ignore everything that follows after the first occurrence of the double quote. Simple fix is to use single quotes instead.

Continue reading
How to leverage queryDef in Adobe Campaign
Adobe Campaign, Marketing Automation

How to Leverage queryDef in Adobe Campaign

7 minutes read

When it comes to programatically selecting records from the database in Adobe Campaign Classic, queryDef emerges as a crucial tool. As a static SOAP method extensively employed in JavaScript, particularly within workflows or web apps, queryDef offers unparalleled capabilities. However, what many may not realize is that there are three distinct implementations of this function. […]

Continue reading
While loop automation
Automation studio, Salesforce Marketing Cloud

SFMC | How to Run an Automation on a Loop

2 minutes read

As many of us are aware, automation in the Salesforce Marketing Cloud can only be scheduled to run at minimum once per hour. While this frequency may suffice for most automations created within the Automation Studio, there are instances where we may require an automation to run continuously, immediately after it completes its previous run. […]

Continue reading
adobe campaign classic how to use sysfilters in data schemas
Adobe Campaign, Marketing Automation

How to use sysFilters in data schemas

2 minutes read

When you run multiple business units on a single Adobe Campaign Classic application, it is beneficial to restrict operators from accessing other business units’ data. We all know that restricting data on form views and with folder access restrictions may not always be successful. The only bulletproof method of managing write or read access rights […]

Continue reading