Swagger demos trow custom 500 / logger REST

Hi Everybody,

I'm using TMS XData\Demos\Swagger demos, and I'm building a REST service on top of it.

Is there any way in service implementation of each function that I can trow 500 and a message instead of a response?

like in C#:

        [HttpPost]
        [Route("/api/session/session-save")]
        public SessionRegistration SaveCurrentSessionRegistration(SessionRegistration Session)
        {
            throw new NotImplementedException();
        }

Also is there any simple way, that I can log all the calls (Request+ Reponse) in the Project main form /memo for example?

Thanks,
Mihai

Hi,

Yes,

uses
   XData.Sys.Exceptions;

(...)

procedure DoSomething(...);
begin
  raise EXDataHttpException.Create(500, 'Your error message');
end;

One way to acomplish that is by using TMSLogging Memo output handler (unit Vcl.TMSLoggingMemoOutputHandler). There are some simple Logging examples in TMS Sparkle\Demos folder.

Just create a Sparkle Middleware and log from there using TMSLogging.

HTH,

1 Like