TXDataClient: response code / exception handling


Is it possible to get the HTTPClient's response status code when using TXDataClient with a service operation? Or to change the default exception text? At the moment I get a default exception message:


XData server request error 
Uri: ...
Status code 403
Error Code: Exception
<Custom text of server message>


Server:

if not CheckComplexPassword(LMessage) then begin    
  raise EXDataHttpException.Create(403, LMessage);
end;  


Client: 

var
  LClient: TXDataClient;
  LLoginService: ILoginService;
  LAnswer: string;
begin
  Result:=False;
  LClient := TXDataClient.Create;
  LClient.Uri:=TSparkleUtils.CombineUrlFast(ClientConfig.ServerURL, 'auth');
  LLoginService := LClient.Service<ILoginService>;
  try
    LAnswer:=LLoginService.ChangePassword(...);
  except
    on E : Exception do
     begin
       ShowMessage('Error: '+E.Message);
     end;
  end;
  Result:=True;
end;


Do I have to parse the exception message manually at the client or is there a simpler way to display the server error message?

Thanks!
You can use:


try
except
  on E: EXDataClientRequestException do
    ShowMessage(E.ErrorMessage);
end;

1 Like

Thank you!