You are not logged in.
Pages: 1
I'm trying to creat a postgres connection using this:
function TRepository.ConnectionClass(pDBConnection: TSqlDBConnectionPropertiesClass): IRepository;
begin
Result := Self;
FConfigDB := pDBConnection.Create(FHost, FDatabase, FUser, FPassword);
VirtualTableExternalRegisterAll(FOrmModel, FConfigDB);
FOrmModel.Props[TAmostra].ExternalDB.MapField('Solicitacao', 'IdSolicitacao');
FRestOrm := TRestServerDB.Create(FOrmModel, SQLITE_MEMORY_DATABASE_NAME);
FRestOrm.DB.Synchronous := smOff;
FRestOrm.DB.LockingMode := lmExclusive;
FRestOrm.Server.CreateMissingTables;
FRestOrm.Server.CreateSqlMultiIndex(TAmostra, ['empresa', 'numero'], true, 'sk_amostra_01');
FRestOrm.Server.CreateSqlMultiIndex(TSolicitacao, ['empresa', 'numero'], true, 'sk_solicitacao_01');
FRestOrm.Server.TrackChanges([TEmpresa, TUsuario, TAmostra,
TRack, TEvento], TMyHistory, 100, 10, 65536);
end;
But it's returning an error: Project SorotrackAPI.exe raised exception class ESqlDBPostgres with message 'TSqlDBPostgresLib' Exec failed '. Can someone help me to find what's wrong?
Offline
AB,
I found the error, but why it dont appear on message box?
tnks.
Offline
It sounds like if errCode seems incorrect in the context.
Please try with https://github.com/synopse/mORMot2/commit/a0e5ce27
Offline
Tnks AB.
There are something midleware on momot to exception´s treatment?
My client Rest receive:
{
"errorCode": 400,
"errorText": "Bad Request"
}
I whould like receive errorText with real information or treat it before return to rest client.
Offline
Sorry, I didn't ask the proper question.
The error appears in the log:
0000000044FC141D EXC ESqlDBPostgres {Message:"TSqlDBPostgresLib Exec failed: 23503 [ERROR: update or delete on table \"empresa\" violates foreign key constraint \"fk_posto_01\" on table \"posto\"\nDETAIL: Key (id)=(1) is still referenced from table \"posto\".\n]",Statement:null} [TAppRestHttpSrv 8081v1 THttpSrv] at ad04c1
But this error cannot be caught by a try except in my application.
function TServiceBase.Delete(pOrmClass: TOrmClass; pId: Int64): TServiceCustomAnswer;
var
vErros: RawUtf8;
begin
if not GlobalRepository.Delete(pOrmClass, pId, vErros) then
Result := ReturnCannotDeleteRecord(StringToUtf8(vErros), HTTP_BADREQUEST);
end;
....
function TRepository.Delete(pOrmClass: TOrmClass; pId: Int64; var pErros: RawUTF8): Boolean;
begin
pErros := EmptyStr;
try
Result := FRestOrm.MemberExists(pOrmClass, pId)
and FRestOrm.Delete(pOrmClass, pId); <<<<< into here generate exception
except on E: Exception do
begin
Result := False; <<<<<<<< never quick here
pErros := E.Message;
end;
end;
end;
How to capture this error message so you can send on TServiceCustomAnswer?
I looked through the code and documentation and didn't find in IRestORM or any other class that had an event or property with LastError
Offline
Note that it is usually a wrong approach to send back all the detailed error information to a client.
This is most of the time confusing for the end user, and may lead to security risks.
So it is on purpose that IRestOrm methods are encapsulating the row database exception, and only return an error code - false for Delete().
But you can retrieve the last raw DB exception text on the current thread by calling the GetDbError function from mormot.db.core, if you really want to send back some content.
Offline
I know, i dont want send detailed error information to a client, but i need show something. client need know the cause to not delete or update or insert the record.
There are some event or a method that can i should override to treat whatever type of exception on rest service?
Offline
The cause should be done in your business logic, and returned explicitly, not from an exception message.
The exception message is likely to change from one DB to another. Don't make your persistence logic specific. Or don't use the ORM.
Offline
Pages: 1