You are not logged in.
Hi,
I call insert method from interface base service, when primary key field is duplicate server return error like below:
How can I get http rersponse code. after calling I.Insert(LInvoice);
TInterfacedObjectFakeClient.FakeCall(IInvoiceService.Insert) failed: '{
"errorCode":500,
"error":
{"EZSQLException":
{
"ClassName": "EZSQLException",
"Address": "073e8890",
"Message": "SQL Error: Duplicate entry '10' for key 'PRIMARY'"
}}
}'
procedure TfrmInvoice.Button1Click(Sender: TObject);
var
I: IInvoiceService;
LInvoice: TInvoice;
begin
if HttpClient.Services['InvoiceService'].get(I) then
begin
LInvoice.code := '10';
LInvoice.descr := 'test';
I.Insert(LInvoice);
end;
end;
Last edited by anouri (2024-11-27 09:21:17)
Offline
With interface-based services, by default you will always get either 200 or 500.
And do not try to get the HTTP status code with interfaces-based services: it would induce a dependency to HTTP, which we want to avoid by using interfaces and their abstraction.
You may implement the service without any remote access involved.
Catch it in the server code, and let the method return false.
You can add an output string value for addition information, or an enumeration for the kind of error.
Offline
I changed insert method and solved:
function Insert(const AInvoice: TInvoice): TServiceCustomAnswer ;
Thank you.
Offline