Jump to content

Recommended Posts

    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?

 

 

2025-05-30_113359.png

Share this post


Link to post

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

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

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 by Die Holländer

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
OSZAR »