Customized HTML Error Message

Without further specification AFP will return messages of Spartan brevity to the browser. While they may do the job it is probably not what you have in mind. This is why AFP can be configured to return any HTML page you want. You can define this HTML file under config/afp/server/error in afp.config. You can set this in the ControlCenter on the Server screen.

For added flexibility in error cases, you may use TEXTMERGE() expressions in these HTML files. With the help of EXECSCRIPT() you can even execute FoxPro code in such a file. In the following example a detailed error message will be sent if the incoming request was localhost; if the access was made from outside a generic message will be embedded. The expressions may not include line breaks.

<<IIF(VarType(Request=="O",IIF(Lower(Request.ServerVariables("HOST_NAME"))=="localhost",Error.ErrorHtml(),FileToStr(Path.MakePath("%root%\500.html"))),"<HTML>…</HTML>")>>

Since an error message can occur at any time you will have to make sure that the AFP objects you wish to access actually exist. To check object REQUEST will suffice, as all objects are readied at virtually the same time. You can also use this file to deliver the standard Web server error messages for various HTTP errors. This could be done throughout the following pages:

<<IIF(VarType(Error)=="O" and File("C:\AFP3\"+Transform(Error.nHTTPError)+".htm"), FileToStr("C:\AFP3\"+Transform(Error.nHTTPError)+".htm"), FileToStr("C:\AFP3\Error.htm"))>>

Thus, if a non-existent file was specified C:\AFP3\404.htm would be sent; in case of HTTP error 500 this would be C:\AFP3\500.htm. You may of course run your own error programs and log error messages in a table, send them out as e-mails or notify the webmaster of certain errors through SMS messages.