• Error not caught if contextReload("") is issued in the SSJS

    By miguel calvo 1 decade ago

    Hi Paul,

    I'm testing your library and I'm having a problem with catching an error in an openDocument data event in an XPage
    

    try{

     openLogEvent("Text", null, 1 );
    //Code that generates a Runtime error
    

    }catch(e){

    openLogBean.addError(e,null);
    context.redirectToPage("aDifferentPage.xsp");
    

    }

    I've tested the same code in a different event in a different page and it seems to work, but in this case neither openLogEvent nor openLogBean generate any document in OpenLog.nsf. If I comment the redirection line, everything seems to be fine.

    In which events can Xpages OpenLog can be used ?

    By the way, I'm using Domino Designer 9.0.1 against IBM Domino 8.5.3.

    Regrads,
    Miguel

    • By Paul S Withers 1 decade ago

      I can understand why that's happening. The errors are added to requestScope when the code runs in any of the relevant lifecycle phases. The PhaseListener then picks up that requestScope object during the Render Response phase.

      The problem is the redirectToPage() aborts the current lifecycle, points to the new page, which clears requestScope and runs that page's Page Load and Render Response phases. It's the same reason Jesse Gallagher uses flash scopes to pass messages between pages.

      What do you think of the idea of additional methods - openLogBean.redirectToPage(String) and openLogBean.redirectToUrl(String)? That way, the PhaseListener can handle the redirect after the errors have been logged.

      One additional question: in this scenario, how do you notify the user? I'm trying to identify whether you would need the logged error message(s).

      It's not going to be possible with the current functionality to give the relevant message to the user, because requestScope is lost. But it may be possible to retrieve them and add to a sessionScope variable (though it could be tricky to clear that again!).

      • By miguel calvo 1 decade ago

        Hi Paul,

        I was thinking of a way to "delay" the redirect, after catching the error. It seems that openLogBean.redirectToPage(String) could be a good idea.
        Regarding the user notification, the error message is saved in an sessionScope variable that is shown and cleared in "aDifferentPage.xsp". If it was in a openLog variable you could have a method to clear it. So the developer would need to clear it manually, but no problem involved.
        

        Being able to use openLogBean.redirectToPage(String) would be a nice solution.
        Thanks,

        • By miguel calvo 1 decade ago

          Solved temporarily by issuing:
          context.redirectToPage(“aDifferentPage.xsp”, false);

          With this syntax, the error event gets logged, despite it shows the wrong XPage name in the log database.
          Additionally, with this redirection, the browser doesn´t change the URL.

          • By miguel calvo 1 decade ago

            Hi Paul,
            I've done further testing. I'm not being able to use

            openLogBean.addError(e,null);
            on querySaveEvent and postSaveEvent.
            I guess it has something to do with the redirection problem.

            • By Paul S Withers 1 decade ago

              I'll look at storing the bean in sessionScope and clearing as required. It's not an ideal solution for performance reasons, but it may log the error. However, I'm not sure how I'll be able identify the correct page of the error.
              I may be able to see something from the PhaseListener for the querySaveEvent and postSaveEvent that helps identify if it's redirecting.

              • By Paul S Withers 10 years ago

                The bean is now stored in sessionScope, so should store the information, but it may log for the page being loaded rather than the page being redirected from.