mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 02:29:19 +02:00
* Error event implemented
git-svn-id: trunk@15861 -
This commit is contained in:
parent
782643789b
commit
7195d8c883
@ -26,12 +26,15 @@ type
|
|||||||
|
|
||||||
{ TExtJSJSONDataFormatter }
|
{ TExtJSJSONDataFormatter }
|
||||||
TJSONObjectEvent = Procedure(Sender : TObject; AObject : TJSONObject) of Object;
|
TJSONObjectEvent = Procedure(Sender : TObject; AObject : TJSONObject) of Object;
|
||||||
|
TJSONExceptionObjectEvent = Procedure(Sender : TObject; E : Exception; AResponse : TJSONObject) of Object;
|
||||||
|
|
||||||
TExtJSJSONDataFormatter = Class(TExtJSDataFormatter)
|
TExtJSJSONDataFormatter = Class(TExtJSDataFormatter)
|
||||||
private
|
private
|
||||||
FAfterDataToJSON: TJSONObjectEvent;
|
FAfterDataToJSON: TJSONObjectEvent;
|
||||||
FAfterRowToJSON: TJSONObjectEvent;
|
FAfterRowToJSON: TJSONObjectEvent;
|
||||||
FBeforeDataToJSON: TJSONObjectEvent;
|
FBeforeDataToJSON: TJSONObjectEvent;
|
||||||
FBeforeRowToJSON: TJSONObjectEvent;
|
FBeforeRowToJSON: TJSONObjectEvent;
|
||||||
|
FOnErrorResponse: TJSONExceptionObjectEvent;
|
||||||
FOnMetaDataToJSON: TJSONObjectEvent;
|
FOnMetaDataToJSON: TJSONObjectEvent;
|
||||||
procedure SendSuccess(ResponseContent: TStream; AddIDValue : Boolean = False);
|
procedure SendSuccess(ResponseContent: TStream; AddIDValue : Boolean = False);
|
||||||
protected
|
protected
|
||||||
@ -61,6 +64,8 @@ type
|
|||||||
Property AfterDataToJSON : TJSONObjectEvent Read FAfterDataToJSON Write FAfterDataToJSON;
|
Property AfterDataToJSON : TJSONObjectEvent Read FAfterDataToJSON Write FAfterDataToJSON;
|
||||||
// Called just before response object will be streamed (response passed to handler).
|
// Called just before response object will be streamed (response passed to handler).
|
||||||
Property BeforeDataToJSON : TJSONObjectEvent Read FBeforeDataToJSON Write FBeforeDataToJSON;
|
Property BeforeDataToJSON : TJSONObjectEvent Read FBeforeDataToJSON Write FBeforeDataToJSON;
|
||||||
|
// Called when an exception is caught and formatted.
|
||||||
|
Property OnErrorResponse : TJSONExceptionObjectEvent Read FOnErrorResponse Write FOnErrorResponse;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -343,6 +348,8 @@ begin
|
|||||||
If Length(L)>0 then
|
If Length(L)>0 then
|
||||||
ResponseContent.WriteBuffer(L[1],Length(L));
|
ResponseContent.WriteBuffer(L[1],Length(L));
|
||||||
Resp.Add(RowsProperty,TJSONArray.Create());
|
Resp.Add(RowsProperty,TJSONArray.Create());
|
||||||
|
If Assigned(FOnErrorResponse) then
|
||||||
|
FOnErrorResponse(Self,E,Resp);
|
||||||
finally
|
finally
|
||||||
Resp.Free;
|
Resp.Free;
|
||||||
end;
|
end;
|
||||||
|
@ -38,6 +38,8 @@ Type
|
|||||||
|
|
||||||
{ TExtJSXMLDataFormatter }
|
{ TExtJSXMLDataFormatter }
|
||||||
TXMLElementEvent = Procedure (Sender : TObject; AElement : TDOMElement) of object;
|
TXMLElementEvent = Procedure (Sender : TObject; AElement : TDOMElement) of object;
|
||||||
|
TXMLExceptionObjectEvent = Procedure(Sender : TObject; E : Exception; AResponse : TDOMElement) of Object;
|
||||||
|
|
||||||
TExtJSXMLDataFormatter = Class(TExtJSDataFormatter)
|
TExtJSXMLDataFormatter = Class(TExtJSDataFormatter)
|
||||||
private
|
private
|
||||||
FAfterDataToXML: TXMLElementEvent;
|
FAfterDataToXML: TXMLElementEvent;
|
||||||
@ -45,6 +47,7 @@ Type
|
|||||||
FBeforeDataToXML: TXMLElementEvent;
|
FBeforeDataToXML: TXMLElementEvent;
|
||||||
FBeforeRowToXML: TXMLElementEvent;
|
FBeforeRowToXML: TXMLElementEvent;
|
||||||
FDP: String;
|
FDP: String;
|
||||||
|
FOnErrorResponse: TXmlExceptionObjectEvent;
|
||||||
FReP: String;
|
FReP: String;
|
||||||
FRP: String;
|
FRP: String;
|
||||||
function IsDocumentStored: boolean;
|
function IsDocumentStored: boolean;
|
||||||
@ -74,6 +77,8 @@ Type
|
|||||||
Property BeforeDataToXML : TXMLElementEvent Read FBeforeDataToXML Write FBeforeDataToXML;
|
Property BeforeDataToXML : TXMLElementEvent Read FBeforeDataToXML Write FBeforeDataToXML;
|
||||||
// Called after all rows are appended to root element (passed to handler).
|
// Called after all rows are appended to root element (passed to handler).
|
||||||
Property AfterDataToXML : TXMLElementEvent Read FAfterDataToXML Write FAfterDataToXML;
|
Property AfterDataToXML : TXMLElementEvent Read FAfterDataToXML Write FAfterDataToXML;
|
||||||
|
// Called when an exception is caught and formatted.
|
||||||
|
Property OnErrorResponse : TXmlExceptionObjectEvent Read FOnErrorResponse Write FOnErrorResponse;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -148,6 +153,8 @@ begin
|
|||||||
C.AppendChild(XML.CreateTextNode(E.Message))
|
C.AppendChild(XML.CreateTextNode(E.Message))
|
||||||
else
|
else
|
||||||
C.AppendChild(XML.CreateTextNode(SerrNoExceptionMessage));
|
C.AppendChild(XML.CreateTextNode(SerrNoExceptionMessage));
|
||||||
|
If Assigned(FOnErrorResponse) then
|
||||||
|
FOnErrorResponse(Self,E,El);
|
||||||
WriteXMLFile(XML,ResponseContent);
|
WriteXMLFile(XML,ResponseContent);
|
||||||
Finally
|
Finally
|
||||||
XML.Free;
|
XML.Free;
|
||||||
|
Loading…
Reference in New Issue
Block a user