Jump to content
KostasR

MARSWebServer Service error logging

Recommended Posts

Hello All,

 

I would like to log errors.
The TMARSActivation.RegisterInvokeError method in Server.Ignition seems to be suitable for this. It is called in the event of an error. But "AActivation.Method" is not assigned, so nothing is logged.
Does anyone have any idea how AActivation.Method can be assigned?

 

TMARSActivation.RegisterInvokeError(
      procedure (const AActivation: IMARSActivation; const AException: Exception; var AHandled: Boolean)
      var
        LErrorObj: TJSONObject;
      begin

        if Assigned(AActivation.Method) then
                    ^^^^^^^^^^^^^^^^^^               
        begin
          LErrorObj := TJSONObject.Create;
          try
            LErrorObj.WriteStringValue('error', AException.Message);
            LErrorObj.WriteStringValue('resource', AActivation.Resource.Name);
            LErrorObj.WriteStringValue('method', AActivation.Method.Name);
            LErrorObj.AddPair('url', AActivation.URL.ToJSONObject);

            AActivation.Response.ContentType := 'application/json';
            AActivation.Response.Content := LErrorObj.ToJSON;

            FThreadFileLog.Log(#13#10 + LErrorObj.ToString);

            AHandled := True;
          finally
            LErrorObj.Free;
          end;
        end;

      end
    );

Regards,

  Kostas

Share this post


Link to post

Hi Kostas,

the MARSWebServer demo has been created way before the InvokeError mechanism has been introduced.

The resource takes care to send a 404 response when a URL is not matching a file system entry (no actual error is raised, a custom response is sent). This means it's unlikely you'll ever get to the InvokeError anonymous handler you registered. You have a chance to have it called if you are addressing a non existent resource (different from helloworld).

 

If you will explain me your needs we may improve the demo or build a new one.

 

Sincerely,

Andrea

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
×