Custom error message

Hi, in one of our services we use Sparkle/XData. When an endpoint call has invalid information in the body we raise an XDataHTTPException:

raise EXDataHTTPException.Create(422, '-112110', Format(rc_SchijfErrorProcBedrijven, [IntToStr(nErrorCount)]) );

This results in a response 422 with body:
{
"error": {
"code": "-112110",
"message": "Pre-processing the companies resulted in 1 problems"
}
}

However we would like to be able to show more error details to the clients, like:
{
"error": {
"code": "-112110",
"message": "Pre-processing the companies resulted in 2 problems",
"errors": [
{
"domain": "Company",
"reason": "required",
"message": "Company code missing (Albert Heijn FIL: C0)"
},
{
"domain": "Company",
"reason": "invalid",
"message": "Company code invalid (Albert Heijn FIL: C0)"
}
]
}
}

Is this somehow possible?

Seems using the OnModuleException in combination with re-raising gives Sparkle the opportunity to prcocess the Response. Not sure if this is the best/only way to go, but then we can manually set the response body

  FXDataServerModule.Events.OnModuleException.Subscribe(
    procedure(Args: TModuleExceptionArgs)
    begin
      if Args.Exception is EXDataHTTPException then
      begin
        Args.Action := TModuleExceptionAction.RaiseException;
      end;
    end
  ); 

from sparkle:

Try
Next(Context);
Except
on E: EXDataHTTPException do
begin
Context.Response.StatusCode := 422;
Context.Response.Close(TEncoding.UTF8.GetBytes(E.ErrorCode));
end;
End

I personally prefer using Args.Action := TModuleExceptionAction.Ignore and then you send your custom message manually. You can then send the error message in any format you want.