You are not logged in.
Pages: 1
why it is not possible get url parameters in onError?
Ctxt.parameters is empty here
Offline
Yes exactly
Offline
there is no Uri. but there are Url = roort\CustomerService\Delete
Ctxt.Call^.InBody is unterminated json. {"cust_code"
error reurned from mysql server
Cannot delete or update a parent row: a foreign key constraint fails (`passak_utf`.`scm_sorder_cust_item`, CONSTRAINT `scm_sorder_cust_item_fk1` FOREIGN KEY (`sale_order`, `sorder_line_no`) REFERENCES `scm_sorder_det` (`sale_order`, `line_no`) ON UPDATE CASCADE)
Last edited by anouri (2025-11-23 11:46:20)
Offline
All this is as intended.
But anyway, the error is to be caught with a try..finally in your own method code.
No in OnErrorUri callback.
Note: you can get the DB error from GetDbError() function of mormot.db.core.pas.
Offline
True, but I wanted to raise errors in different places in the application if possible and handle them in only one place. This way, I would avoid writing hundreds of try excepts and centralize all error handling in one place.
Offline
I am afraid it may lead to a confusion between logic error and database error.
As a better alternative, you may encapsulate the SQL execution into some methods of your own, with a centralized error handling.
Offline
I created a custom exception class containing error codes and messages for handling business errors. However, one limitation I'm facing is that I cannot access URI parameters in this scenario.
Offline
I followed your suggestion:
function DeleteRecord(const ASql: RawUtf8; const Params: array of const; AConnection: TSqlDBConnection; out UpdateCount: Integer): TServiceCustomAnswer;
begin
try
UpdateCount := AConnection.Properties.ExecuteNoResult(ASql, Params);
if UpdateCount = 0 then
begin
Result.Status := HTTP_SERVERERROR;
Result.Content := TErrorDTO.CreateErrorJson('1' , 'no record found');
Exit;
end;
Result.Status := HTTP_SUCCESS;
Result.Content := TUtils.AddCommonHeaderToJSon('[]', true);
except
on E: EZSQLException do
begin
if EZSQLException(E).ErrorCode = 1451 then // foreign key constraint error
begin
Result.Status := HTTP_SERVERERROR;
Result.Content := TErrorDTO.CreateErrorJson('1' , 'record can not be deleted.');
end;
end;
end;
end;Last edited by anouri (2025-11-25 10:37:31)
Offline
Pages: 1