* Error event implemented

git-svn-id: trunk@15861 -
This commit is contained in:
michael 2010-08-20 08:58:13 +00:00
parent 782643789b
commit 7195d8c883
2 changed files with 14 additions and 0 deletions

View File

@ -26,12 +26,15 @@ type
{ TExtJSJSONDataFormatter }
TJSONObjectEvent = Procedure(Sender : TObject; AObject : TJSONObject) of Object;
TJSONExceptionObjectEvent = Procedure(Sender : TObject; E : Exception; AResponse : TJSONObject) of Object;
TExtJSJSONDataFormatter = Class(TExtJSDataFormatter)
private
FAfterDataToJSON: TJSONObjectEvent;
FAfterRowToJSON: TJSONObjectEvent;
FBeforeDataToJSON: TJSONObjectEvent;
FBeforeRowToJSON: TJSONObjectEvent;
FOnErrorResponse: TJSONExceptionObjectEvent;
FOnMetaDataToJSON: TJSONObjectEvent;
procedure SendSuccess(ResponseContent: TStream; AddIDValue : Boolean = False);
protected
@ -61,6 +64,8 @@ type
Property AfterDataToJSON : TJSONObjectEvent Read FAfterDataToJSON Write FAfterDataToJSON;
// Called just before response object will be streamed (response passed to handler).
Property BeforeDataToJSON : TJSONObjectEvent Read FBeforeDataToJSON Write FBeforeDataToJSON;
// Called when an exception is caught and formatted.
Property OnErrorResponse : TJSONExceptionObjectEvent Read FOnErrorResponse Write FOnErrorResponse;
end;
implementation
@ -343,6 +348,8 @@ begin
If Length(L)>0 then
ResponseContent.WriteBuffer(L[1],Length(L));
Resp.Add(RowsProperty,TJSONArray.Create());
If Assigned(FOnErrorResponse) then
FOnErrorResponse(Self,E,Resp);
finally
Resp.Free;
end;

View File

@ -38,6 +38,8 @@ Type
{ TExtJSXMLDataFormatter }
TXMLElementEvent = Procedure (Sender : TObject; AElement : TDOMElement) of object;
TXMLExceptionObjectEvent = Procedure(Sender : TObject; E : Exception; AResponse : TDOMElement) of Object;
TExtJSXMLDataFormatter = Class(TExtJSDataFormatter)
private
FAfterDataToXML: TXMLElementEvent;
@ -45,6 +47,7 @@ Type
FBeforeDataToXML: TXMLElementEvent;
FBeforeRowToXML: TXMLElementEvent;
FDP: String;
FOnErrorResponse: TXmlExceptionObjectEvent;
FReP: String;
FRP: String;
function IsDocumentStored: boolean;
@ -74,6 +77,8 @@ Type
Property BeforeDataToXML : TXMLElementEvent Read FBeforeDataToXML Write FBeforeDataToXML;
// Called after all rows are appended to root element (passed to handler).
Property AfterDataToXML : TXMLElementEvent Read FAfterDataToXML Write FAfterDataToXML;
// Called when an exception is caught and formatted.
Property OnErrorResponse : TXmlExceptionObjectEvent Read FOnErrorResponse Write FOnErrorResponse;
end;
implementation
@ -148,6 +153,8 @@ begin
C.AppendChild(XML.CreateTextNode(E.Message))
else
C.AppendChild(XML.CreateTextNode(SerrNoExceptionMessage));
If Assigned(FOnErrorResponse) then
FOnErrorResponse(Self,E,El);
WriteXMLFile(XML,ResponseContent);
Finally
XML.Free;