Subject Simple way to intercept HTTP server-side errors
From Boris Borzic <bb> <Boris Borzic <bb>>
Date Fri, 24 Apr 2020 14:19:51 -0400
Newsgroups xb2net

Here is a simple way to intercept an HTTP error message just before it's
sent to client. The key is the (logical) 5'th param in xbHTTPErrorHandler
(currently undocumented). The value .F. tells the function to NOT
interrupt program execution with a Break(). The function returns with a
properly formatted error string which you can further modify and/or
display on your server UI.

Certainly, you can write your own custom HttpErrorHandler, however this
solution is only 5 lines.

// initialize HTTP server object
oServer := xbHTTPServer():new( INADDR_ANY, 443, oSSLContext )

oServer:RootDir     := ".\www_root"
oServer:onHttpError := {|e|MyHttpErrorHandler(e)}

// custom HTTP error handler that intercepts the error message
// before it's returned to a client

PROCEDURE MyHttpErrorHandler( oErr )
   Local cErrMsg := xbHTTPErrorHandler(oErr,,,,.f.)
   SendAlert( cErrMsg ) // add your own function here
   Break( cErrMsg ) // returns error message to connected client

Best regards,
Boris Borzic
industrial strength Xbase++ development tools

Recent messages in this thread
.# Simple way to intercept HTTP server-side errors (Current message) Boris Borzic <bb> 24-Apr-2020 02:19 pm