1
0
-1

Hi,

I need to customise the error message that is displayed to a user if there is a prefill error.

Instead of the default message "Sorry An Error Has Occurred", "Groovy Form Prefill Service Error", I would like a custom message like "Data missing from url. Please contact XYZ", or "Data missing from request parameters. Please contact ABC", or other custom messages.

I have added the code to throw new Exception, and that message appears in the TM error logs.

I would like a custom message to also appear to the user.

Thanks

Mark

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Hey Mark, the error page you are seeing is a generic error page that is part of the Space your form is being rendered in. You can find the content for this page by opening your Space in TM (under Forms -> Form Spaces menu) and going to the Pages tab.

       

      You can edit this page to display different or additional information based on the data available on the Error Log object. For example, $errorLog.message will display the message you are passing into the Exception.

      Be aware that the changes you make will effect any other error type that triggers this page also.

      1. Mark Murray

        Hi Ben,

        thanks for the details. I expected that it was a template page, but I couldn't find it in my earlier searching.

        Thanks

      2. Mark Murray

        Hi Ben,

        I've had to revisit this and having some trouble.

        If I simply use the redirectException the displayed message is "Unexpected Error".

        If I use the following code a message is displayed, but not the one I want.

        new ErrorLogService().logError(null, "myUserMessage", "Form Prefill")
        throw new RedirectException("../error.htm")

        The message says NullPointerException.

        This is running in a Groovy script, so I don't have a Class to pass as the first argument.

        How do I set the variables:

        • $errorLog.message
        • $errorLog.userMessage

        It seems I need to set the message in the errorLog (or ErrorLogService) because you can't pass a message to the redirectException, only the target


        Thanks

        Mark

      CommentAdd your comment...
    2.  
      1
      0
      -1

      Hi,

      for anyone who is interested, I managed to get this working.

      I found that using "throw RedirectException" did not work, even after setting errorLogs.

      The solution that worked is to "throw ApplicationException(name, context, message, solution)" and ensure that this code is not within a try/catch block.

      The result is that the message from above gets displayed to the user, finally.

      That approach doesn't fit with the usual error handling approach of catching errors, but it works, so I'll settle on this for now.


      Thanks

      Mark

        CommentAdd your comment...