Tips_tutorials   >   Studiojs201   >   Web Error Handling
We put a Breakpoint near the end of the $construct method if FlagOK was false. Breakpoints, OK, Yes/No, No/Yes messages, and any modal prompts are a big no, no, with web related code. The reason is that the prompt will show up on the server and no response will be sent to the web browser. The Omnis Web App Server will be stuck and unable to responds to any further requests from other web browsers. You get the picture. Someone will have to go to the server, click the OK button on the dialog window before any new requests can be processed. Not a good thing!
We therefore need to add as method to the error handler that we created in and add a new method to oHTMLTools.The error handler has a $promptonceLastError method which opens a modal prompt. We need to add a method which passes back the last error message text, rather than opening a prompt.
; Only return the error message values the first time this method is called.
If iErrorsList.prompted=kFalse
; Set the prompted flag to true to avoid multiple prompts of the same error message.
Calculate iErrorsList.prompted as kTrue
; Pass the error message text and method name to the sender.
Calculate pfRetMssg as iErrorsList.errormssg
Calculate pfRetMethod as con(iErrorsList.libname,'/',iErrorsList.classname,'/',iErrorsList.methodname)
End If
Quit method kTrue
We will add a $retHTMLLastError method to oHTMLTools. This method will get the last error from the error handler, and then format it into an HTML page that is ready to return to the web browser via the Omnis Web App Server.
; Get the last error message logged with the error handler.
Do errhndlr.$getonceLastError(Mssg,Method) Returns FlagOK
If len(Mssg)=0
Calculate Mssg as "An error occured, but was not logged to the error handler. Please notify the webmaster."
End If
Calculate Title as 'Error'
; Prepare the HTML for the body section of the web page.
Begin text block
Text: <h3>[Title]</h3> (Carriage return,Linefeed)
Text: (Carriage return,Linefeed)
Text: [Mssg] (Carriage return,Linefeed)
End text block
Get text block Body
; Prepare the HTML for a web page that displays the error.
Do $cinst.$retHTMLPageTemplate Returns HTML
Calculate HTML as replaceall(HTML,'##TITLE##',Title)
Calculate HTML as replaceall(HTML,'##BODY##',Body)
Do $cinst.$addHTTPContentHeader(HTML)
Quit method HTML
We can now replace the Breakpoint in the $construct method of rtCountryList with a call to oHTMLTools.
If not(FlagOK)
; An error occurred. Get the last error as an HTML page.
Do ioHTMLTools.$retLastErrorHTML() Returns HTML
End If
Quit method HTML