You are not logged in.
Hi,
I have been looking a lot at the mORMot documentation lately as well as making some demo projects. I think it is a great framework! and have started to use it in one or our projects.
I am focusing on the "services as methods" side and not the ORM/DB. I will need to create 3-6 "services" interfaces and each of these will have from 10-50 methods.
I am trying to figure out a good common error/result reporting "mechanism" to use consistently for all these methods.
By error/result reporting I mean how you return information about the method call to the caller. Not errors in the framework, connection etc.
e.g. a method like
procedure AddProduct(aID: string; aName: string; aType: Integer);
could result in errors like:
- Invalid ID/Name/Type
- Product already exists
- Not allowed
My current idea is to use a "generic" record for all methods. Something like
type
TCallResult = packed record
Error: Integer
Severity: TSeverityEnum;
Text: string;
end;
procedure AddProduct(aID: string; aName: string; aType: Integer; out Result: TCallResult);
or
function AddProduct(aID: string; aName: string; aType: Integer): TCallResult;
- Is this a "good" way to implement it or is there a better way (maybe part of the framework)?
- Is using the "out" parameter better/worse than using a function with the record as the result?
br Lars
Offline
You can do this.
It perfectly does make sense.
There is no difference by using an "out" or a function result, for records: in fact, a function result is implemented like a last "out" parameter.
By default, a record will be serialized as text.
A somewhat better may be to use text-based JSON serialization, to have the TCallResult serialized as plain JSON, so will be much able to be consumed with any client (e.g. AJAX).
Thanks for the feedback.
Online