You are not logged in.
Hi,
I have the following service:
function TDBService.ContactDataRecycle(const aUser, aSourceTableName, aDestTableName: RawUTF8;
const aOverwriteOrAppend, aFax, aAnswerMachine, aNoContact: Boolean;
const aDuration: Integer; const aVarTMCondition: RawUTF8): Integer;
begin
if (aSourceTableName = '') then
raise EASOA.CreateUTF8('Invalid parameters: table name=%', [aSourceTableName]);
if Assigned(fTableList.Find(aSourceTableName)) then
ServiceContext.Request.Error('Table % is in use by an outgoing activity', [aSourceTableName]);
end;
but the response is (second if is executed):
{"result":[4206772]}
Is there another way to return custom error code and message ? I want receive the response in the same way that when raising an exception, but with another error code and without raise an exception.
Thanks in advance.
EMartin.
Esteban
Offline
If the error is a fatal error, use an exception.
If the error is a business logic error, use an enumerate, and a custom code (with an optional string).
See e.g. how we defined CQRS services for mORMotDDD.pas.
Corresponding doc is http://synopse.info/files/html/Synopse% … l#TITL_165
Offline
I have existing code without DDD implementation (you were building this).
I'll study how to use DDD and the change of return codes from HTTP to DDD.
But now I have to deliver the work so I'll use exceptions for send message with the error.
Thanks.
EMartin.
Esteban
Offline
Hi ab,
Why ServiceContext.Request.Error(...) is not working in interfaces as Ctxt.Error(...) works in methods ?
Thanks.
EMartin.
Esteban
Offline
Because interface-based services override the Ctxt content at output.
This is how it works.
ServiceContext.Request may be used for input (e.g. retrieve the IP), not for output.
In theory, it is better not to rely on ServiceContext.Request at all, since interface-based services may be executed with ServiceContext.Request=nil, e.g. if they are resolved and executed directly on the server side.
Offline
Thanks ab.
I think that when request is not nil it should be able to send an error response, is another way of override the Ctxt content at output.
My workaround was to use TServiceCustomAnswer creating both the correct response as the incorrect because changing to DDD is much more work for the moment.
EMartin.
Esteban
Offline