KostasR 1 Posted May 30 rsUpdateLicence.PUT( procedure (AContent: TMemoryStream) var LJSONObject: TJSONObject; BirthDateStr, FormattedDate: string; begin JSONValueToStream(LJSONObject, AContent); end, procedure (AResponse: TStream) var LResponse: TJSONObject; begin LResponse := StreamToJSONValue(AResponse) as TJSONObject; try if Assigned(LResponse) then begin begin LicenseRespose := LResponse.ToRecord<TLicenseRespose>(); oResult := WriteData(LicenseRespose); end; finally LResponse.Free; end; end, procedure (AErr: Exception) begin ShowMessage('Error: ' + AErr.Message); // How can I get this error-object? end); How can I receive this error-object for error-handling in this method, see PostMan Image? Share this post Link to post
KostasR 1 Posted June 7 Sorry to ask again: Is there no solution here, or am I asking the wrong question? OnAfterExcute procedure (AErr: Exception) only returns the error message but not the response object like in the method OnExecute procedure (AResponse: TStream) Does anyone have any ideas? Share this post Link to post
Die Holländer 86 Posted June 10 You only show the JSON parsing part. What do you use to perform the Put? (Like TidHTTP?) Share this post Link to post
KostasR 1 Posted June 10 I'm using Andrea Magni's MARS REST API, which is based on Indy and therefore likely uses TidHTTP. The Delphi code I published is the PUT method of the MARS REST API.I'm using Andrea Magni's MARS REST API, which is based on Indy and therefore likely uses TidHTTP. The Delphi code I published is the PUT method of the MARS REST API. Share this post Link to post
Die Holländer 86 Posted June 10 (edited) Maybe this is what you need.. You have to tell TidHTTP that it should return the error JSON message and not only the HTTP error code. Result:=False; idHTTP.Request.ContentType := 'application/json;odata=verbose'; //Tell the idHTTP that it should NOT ignore the (JSON) errormessage returned by the server. idHTTP.HTTPOptions := idHTTP.HTTPOptions + [hoNoProtocolErrorException, hoWantProtocolErrorContent]; //Add the message in a string var. ReceiveData := idHTTP.Put(Param, JsonToSend); if (idHTTP.ResponseCode div 100) = 2 then begin Result:=True; end else Begin //Parse/Show the message aMessage:=CreateErrorMessage(ReceiveData); End; Edited June 10 by Die Holländer Share this post Link to post