#1 2025-11-22 17:56:43

anouri
Member
Registered: 2024-02-11
Posts: 152

accesse Call parameters in ONError?

why it is not possible get url parameters in onError?
Ctxt.parameters is empty here

Offline

#2 Yesterday 07:39:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,293
Website

Re: accesse Call parameters in ONError?

Do you mean TRestServer.OnUriError?

If the exception is raised during the parsing, or there is no parameter, it is nil.
You should be able to use Ctxt.Call^.Uri instead.

Offline

#3 Yesterday 11:34:47

anouri
Member
Registered: 2024-02-11
Posts: 152

Re: accesse Call parameters in ONError?

Yes exactly

Offline

#4 Yesterday 11:38:57

anouri
Member
Registered: 2024-02-11
Posts: 152

Re: accesse Call parameters in ONError?

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 (Yesterday 11:46:20)

Offline

#5 Yesterday 11:59:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,293
Website

Re: accesse Call parameters in ONError?

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

#6 Yesterday 12:08:53

anouri
Member
Registered: 2024-02-11
Posts: 152

Re: accesse Call parameters in ONError?

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

#7 Yesterday 12:12:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,293
Website

Re: accesse Call parameters in ONError?

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

#8 Yesterday 12:26:19

anouri
Member
Registered: 2024-02-11
Posts: 152

Re: accesse Call parameters in ONError?

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

Board footer

Powered by FluxBB