How to change http error code from exceptions

On every exception XData returns http 500 status code.

Before the service is done returning to client, I'd like to be able to change that, for instance based on the exception.

Eg. My Aurelius class raise an 'EValidationError' (it has no knowlege of XData)

XData gets the Exception and returns status code 500

Before returning to client, I'd like to do something like:

if ErrorCode='EValidationError' then // *or* if E is EValidationError ...
  EXDataHttpException.Create(406, E.message); // *or* Context.Response.StatusCode := 406;

Hello, we have implemented such feature in our development branch. This feature will be available in TMS XData version 2.9. If you need this before release, please contact us directly for a patch.

Here is how you should use it:



  Module.Events.OnModuleException.Subscribe(
    procedure(Args: TModuleExceptionArgs)
    begin
      if Args.ErrorCode = 'ValidationError' then
        Args.StatusCode := 406;
    end
  );

Wagner R. Landgraf2018-03-20 20:00:25

Hi Wagner. Thanks for the feedback. That's great news.


Regards,