Error handling in a Try Catch statement fails when using SSJS Platform.Response.Redirect

I am currently facing an issue with threadabortexception in .NET, and despite trying various options, I have not been able to resolve it.

In essence, the Redirect function is throwing errors and landing in the catch block, regardless of whether the second parameter is set to true or false.

The code snippet provided below is just an illustration (although I have encountered this issue a few times in actual projects).

...

       try {

            var TSD = TriggeredSend.Init("DE_Name");
            var Status = TSD.Send(data.subscriber, data.attributes);

            if (Status != "OK") {
                Platform.Response.Redirect(Variable.GetValue("@error_page"));
            } else {
                Platform.Response.Redirect(Variable.GetValue("@thanks_page"));  //<<<-- This redirect throw error
            }
        } catch (err) {
            Platform.Response.Redirect(Variable.GetValue("@error_page")); // <---- here it comes
        }
...

For more information, you can refer to the following resources: 1# https://support.microsoft.com/en-us/help/312629/prb-threadabortexception-occurs-if-you-use-response-end-response-redir

2#

Any suggestions for a workaround would be greatly appreciated.

Answer №1

Although this question may be considered outdated, it is important to continue sharing new discoveries.

The mystery surrounding why the Redirect always triggers an error and how the catch block gets executed baffles me.

Consider this clever workaround:

...

   try {

        var TSD = TriggeredSend.Init("DE_Name");
        var Status = TSD.Send(data.subscriber, data.attributes);

        try { 
            if (Status != "OK") {
                Platform.Response.Redirect(Variable.GetValue("@error_page"));
            } else {
                Platform.Response.Redirect(Variable.GetValue("@thanks_page"));  //<<<-- This redirect throw error
            }
        } catch(e) {}

    } catch (err) {
        Platform.Response.Redirect(Variable.GetValue("@error_page")); // <---- here it comes
    }
...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a quiz with just one question in React: A step-by-step guide

How can I add the functionality to handle correct and incorrect answers? I've designed a single-question quiz with multiple options. The Quiz component has been created. See the code snippet below: Quiz Component export default function Quiz(props) { ...

The HTML grid is causing an irritating excess space on the right side of my website

After brainstorming an idea, I decided to create this website for testing purposes. However, the grid layout seems to be causing an unwanted margin on the right side of the page that is not associated with any HTML tag, disrupting the zoom functionality. ...

Unable to get the code for automatically refreshing a DIV every 5 seconds to function properly

My Inquiry Regarding DIV Refresh I am having issues with the code below that is supposed to automatically refresh the DIV id refreshDiv every 5 seconds, but it is not working as expected. <div id ="refreshDiv" class="span2" style="text-align:left;"&g ...

What steps can be taken to restrict a user's access to the main page unless they are logged in?

I have created sign up and login pages using JavaScript, HTML, and PHP with a database. After a user successfully logs in on the login page, the following code is executed: sessionStorage.setItem('logged','loggedIn'); The user is then ...

Using React to update an existing array of objects with a new array containing objects of the same type

My issue involves an array in a class's state, referred to as A. A is populated with objects of type B through the function f in the constructor. Subsequently, I create a new array of objects of type B called C using f and new data. Upon setting the s ...

When working with express.js, the following error may occur: Uncaught Error [ERR_HTTP_HEADERS_SENT]: Unable to modify headers after they have been sent to the client

Seeking assistance for resolving this issue. The purpose of this code is: Update the artist using the specified artist ID and data from the request body, then save it to the database. Return a 200 response with the updated artist in the response body. If ...

Leveraging React Hooks for managing the Data Provider and Data Context functionality

Currently, I am revamping my DataProvider by upgrading it from a class component to a functional component utilizing React Hooks. I suspect that the issue lies in how I am setting up my context consumer, but I am struggling to find an effective way to tes ...

The click event triggered by the onclick clone/function may not always activate the click handler

As a newcomer in the JavaScript domain, I am encountering an issue where the first clone created after clicking 'add more' does not trigger my click me function. However, every subsequent clone works perfectly fine with it. What could be causing ...

Tips for transferring data from an Ajax response object into an element

Everything is working smoothly with my ajax function. It successfully fetches multiple objects from the database, all of which have attributes like supplier_name and supplier_id. The response object then places them into the correct element on the web page ...

Disregard the significance of radio buttons - iCheck

I have been attempting to retrieve values from radio buttons (using iCheck), but I am consistently only getting the value from the first radio button, while ignoring the rest. Despite following what seems to be correct code theory, the output is not as exp ...

When using JavaScript to style.display = "block", the Bootstrap-4 column layout may experience a display break

My div is initially displaying properly in one row at the beginning. However, when the user changes the select option to "b" and then back to "a," the display breaks. The two texts "my left side text" and "my right text" are displayed on two lines, one be ...

Avoiding the backslash in JavaScript

<script type="text/javascript"> console.log(#Fileurl#); jQuery.ajax({ url: "http://xyz:8800/aaa/bbb/ccc", type:'POST', dataType: 'JSON', data:{"file":"#Fileurl#"}, success: function ...

The table remains visible during an AJAX call

I need assistance with removing a table after successful deletion triggered by an AJAX to PHP call. Below is the function provided: list.php <script type="text/javascript"> function massDelete() { if (!confirm("Are you sure")) ...

Encountering an issue with the `className` prop not matching when deploying to Heroku, yet the functionality works perfectly when testing locally

I encountered this specific error message: The className property did not match. On the server: "jss1 jss5" Client side: "makeStyles-root-1 makeStyles-root-5" This issue only arises when deploying to Heroku. Locally, everything runs ...

Transferring information from an external JavaScript file to a Vue component

I am currently facing an issue with passing data from an external file called data.js to the component for its usage. The error I'm encountering states that the data is not defined. Below is the content of my data.js file: const data = [ { cha ...

Tips for swapping out the content within a "li" element

I am dealing with a situation where I have approximately 100 pages, all containing an <ul> tag, but the issue is that I need to enclose each list item within a <span> tag. Below is the code snippet I have tried: <ul style="list-style-type: ...

Customize Your Calendar: A Guide to Disabling Dates with Pikaday.js

Wondering how to disable specific days on a calendar? Look no further! Here's a solution using the `disableDayFn` option from Github: disableDayFn: callback function that gets passed a Date object for each day in view. Should return true to disable s ...

Displaying components in Vue 2 using data from an ajax call

How can components retrieved from an ajax response be rendered? For instance, suppose I have registered a component called "Test" and within the ajax response I encounter: <p>dummy paragraph</p> <test></test> <!-- vue component ...

Struggling to integrate Material UI (MUI) into my React application

I have followed all the necessary steps to install materialUI, emotion/react, and emotion/styled in my react app. However, I am encountering an issue where MUI does not seem to work properly. There are no errors displayed on the console or webpage, but not ...

Generating a Vue JS component on the fly

How can I dynamically create a component in Vue JS on click and then route to that component in a single click event? I am using Vue 3 and my current code snippet looks like this: methods:{ routerClick(value){ console.log("The number is "+value) ...