Atozed Forums

Full Version: IWError.html not rendered from raised exception in servercontroller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
XE7 - IW 14.2.10 bundled.

Because using the UserSessionUnit (is a DM) and that exceptions are handled during the creation method I use a UserSession.Initialize method to process all data connections. If there are any exceptions they are raised back into the caller. In this case the ServerController. In IW 12 it used to display the IWError.html from the templates folder.
This does not work anymore from the  Servercontroller. It does work if the exception is in a form though.
The exception does properly reach the SeverController.OnException.

The ExceptionLogger is creating the file as expected however, the user only sees a blank page. Not very helpfull. Sad

So, how do we render our custom IWError.html with the merged information when the exception is in the ServerController?

Thank you,
-Craig
Where are you calling UserSession.Initialize from?
Hello Kudzu,

Thank you for the reply.

In the IWServerControllerBaseNewSession event.

if GSessions.IsValidSession(ASession) then
    begin
      ASession.Data := TIWUserSession.Create(nil, ASession);

      UserSession.Initialize;
    end;

A mainform is set by default.

In the IWServerControllerBaseGetMainForm event  I have to test for parameters and if valid, assign a different form and serve up a pdf document that is stored in blob field. If the params are valid but the doc does not exist then I TerminateAndRedirect with a message.  If no params or the params are not valid then they are ignored and the default mainform is displayed.

Thank you for your assistance!

Craig
Hi Craig, in this demo, you can create a personalized exceptions.
Hi Jose,

I had looked at and tested that demo. Same issue... you get a blank page if the exception occurs within the servercontroller. Simple test is to Raise Create.Exception('test') in the newsession event right after the UserSession is created.

Thanks,
Craig
IWServerControllerBaseNewSession

There were some changes after IW12. This event doesn't necessarily happen within the flow that you think it does or the same way as 12.

If the demo doesn't show what you need, let us know and we can look further to help you achieve what you desire.
Hi Kudzu,

What I need is to be able to display our Custom Error in HTML window to user. Whether this occurs as an exception via the UserSession object, ServerConroller object or a form. We want to maintain consistancy. I have a workaround, though it just does not seem like the proper way. I can't use the ServerController.OnException because if that is assigned it bypasses the form (even when Handled is true).
So this ends up a blank screen. Can't TerminateAndRedirect there also it just stays blank.

The workaround is to test for exception when creating UserSession and Initilization if so, store the E.message to ServerController public property ErrorMsg and test for non-empty in creation of form. If so, then webApplication.terminate and Raise new execption with the ErrorMsg value and reset ErrorMsg to emptystr.

This still leaves holes though and is not a complete solution.

Thanks,
Craig
Is this exception being raised when creating a new session? 

I'm failing to reproduce this. Do you have a test case?
Hi Alexandre,

In my case:
<code>
procedure TIWServerController.IWServerControllerBaseNewSession(
ASession: TIWApplication);
begin
if GSessions.IsValidSession(ASession) then
begin
ASession.Data := TIWUserSession.Create(nil, ASession);
UserSession.Initialize; // most likely it will occur here due to invalid connectionname, sql access denied, etc...
end;
end;
</code>

In your Demo SubclassingExceptionRenderer :
<code>
procedure TIWServerController.IWServerControllerBaseNewSession(
ASession: TIWApplication);
begin
ASession.Data := TIWUserSession.Create(nil);
raise Exception.Create('test Error Message'); // no message appears and the browser is blank
end;
</code>

Thank you,
Craig
(04-05-2019, 12:05 AM)Craig Burke Wrote: [ -> ]Hi Alexandre,

In my case:
<code>
procedure TIWServerController.IWServerControllerBaseNewSession(
 ASession: TIWApplication);
begin
 if  GSessions.IsValidSession(ASession) then
   begin
     ASession.Data := TIWUserSession.Create(nil, ASession);
     UserSession.Initialize;    // most likely it will occur here due to invalid connectionname, sql access denied, etc...
   end;
end;
</code>

In your Demo SubclassingExceptionRenderer :
<code>
procedure TIWServerController.IWServerControllerBaseNewSession(
 ASession: TIWApplication);
begin
 ASession.Data := TIWUserSession.Create(nil);
 raise Exception.Create('test Error Message');  // no message appears and the browser is blank
end;
</code>

Thank you,
Craig

The issue here is that the server is returning status code 500 (which is correct), however the code loading the page expects status code 200. Latest IW 15 code base has a different code and it works, but I'll need to back port the fix to IW 14 code base. I'll see if it is at least feasible and get back to you, OK?
Pages: 1 2