|
<< Click to Display Table of Contents >> Navigation: Demos > XIV > Delphi > CustomizingExceptions > SubclassingExceptionRenderer > MyExceptionRenderer.pas |
unit MyExceptionRenderer;
interface
uses
SysUtils, Classes, IW.Http.Request, IWExceptionRenderer; // all these units are required here
type
TMyIWExceptionRenderer = class(TIWExceptionRenderer)
public
class var Redirect: Boolean;
public
class function RenderHTML(AException: Exception; ARequest: THttpRequest): string; override;
end;
implementation
uses
IWException, // required to use EInvalidSession
IWUtils; // required to use HtmlRedirect function
{ TMyIWExceptionRenderer }
class function TMyIWExceptionRenderer.RenderHTML(AException: Exception;
ARequest: THttpRequest): string;
begin
// here we just return some VALID HTML as a string
// This HTML will be presented to the user as is.
if AException is EInvalidSession then begin // this HTML will be sent back to browser when a Timeout occurs
if Redirect then begin
Result := HtmlRedirect('http://www.atozed.com'); // redirect to another domain/site
end else begin
Result := '' + // otherwise use a custom page
'' +
'' +
'' +
'Application timeout' +
'' +
'#error {' +
'width: 40%;' +
'max-width: 400px;' +
'min-width: 200px;' +
'height: 20%;' +
'min-height: 170px;' +
'max-height: 400px;' +
'margin: 8% auto;' +
'border: 6px solid #006600;' +
'padding: 20px;' +
'font-family: Arial, Helvetica, sans-serif;' +
'color: black;' +
'background-color: #fefefe;' +
'}' +
'' +
'' +
'' +
''+
'Timeout error' +
'A timeout occurred! Please restart the application.' +
'' +
'' +
'';
end;
end else begin // all other unexpected errors will receive this error page
Result := '' +
'' +
'' +
'' +
'Application Error' +
'' +
'#error {' +
'width: 40%;' +
'max-width: 400px;' +
'min-width: 200px;' +
'height: 20%;' +
'min-height: 170px;' +
'max-height: 400px;' +
'margin: 8% auto;' +
'border: 6px solid #FF0000;' +
'padding: 20px;' +
'font-family: Arial, Helvetica, sans-serif;' +
'color: #AC292E;' +
'background-color: #fefefe;' +
'}' +
'' +
'' +
'' +
''+
'Application Error' +
'' +
'' +
'' +
'';
end;
end;
initialization
// install TMyIWExceptionRenderer as the default IWExceptionRenderer
SetExceptionRendererClass(TMyIWExceptionRenderer);
// if True, all session timeout errors will be redirected to an external site (in this demo, www.atozed.com)
TMyIWExceptionRenderer.Redirect := False;
end.