Forums

Forums / General Discussions / Handling error on form loading

Handling error on form loading

2 posts, 1 answered
  1. Krishna Hari
    Krishna Hari avatar
    65 posts
    Registered:
    05 Dec 2019
    10 Jan 2023
    Link to this post
    I have a form which loads using custom query string. I want to capture the error when a n invalid string is passed. Console error  ",,,With Id = ffbd1be8-b47c-ed11-815a-005056af1125 Does Not Exist" but How can I write a function to redirect a page on such cases to an error page
  2. Tariq Salim
    Tariq Salim avatar
    11 posts
    Registered:
    04 Jul 2022
    Answered
    20 Jan 2023 in reply to Krishna Hari
    Link to this post
    Hello Krishna,


    Please try the following, write a function to handle the error and redirect the page to an error page in the following way:

    function handleError(errorMessage) {
      if (errorMessage.includes("Does Not Exist")) {
        window.location.replace("https://your-error-page.com");
      }
    }

    try {
      // your code to load the form with custom query string
    } catch (error) {
      handleError(error.message);
    }

    In this code, we first define a function handleError that takes in an error message as a parameter. The function checks if the error message contains the string "Does Not Exist". If it does, it uses the window.location.replace method to redirect the user to the error page.
    Next, we wrap the code to load the form with custom query string in a try-catch block. If an error occurs, the catch block will catch it and pass the error message to the handleError function.

    Let us know if this helps resolve your issue.


    Best Regards,
    Tariq
    Last modified on 31 Jan 2023 21:01 by Tariq Salim
2 posts, 1 answered