#1 mORMot 2 » OpenAPI Generator Error Handling » Yesterday 12:43:46

MarcelG
Replies: 1

Hello, how can I handle errors with the OpenAPI Client Generator Code?

This is my current approach where I changed fClient to public:

procedure TForm1.HandleJsonClientError(const Sender: IJsonClient; const Response: TJsonResponse; const ErrorMsg: shortstring);
begin
  fehlerAufgetreten := true;
  ShowMessage('Error: ' + ErrorMsg);
end;

function GetPet(PetId: integer): string;
var
  Pet: TPet;
  jerror: TOnJsonClientError;
begin
 Pet := Client.GetPetById(PetId);
 jerror := Form1.HandleJsonClientError;
 Form1.fehlerAufgetreten := false;
 Client.fClient.Request('GET', '/api/pet/%', [PetId], [], [],Pet, TypeInfo(TPet) ,jerror);
  if not Form1.fehlerAufgetreten then
    Result := 'ID:' + InttoStr(Pet.Id) + ', Name:' + Pet.Name + ', Status:' + GetEnumName(TypeInfo(TEnumPetStore1), Ord(Pet.Status)) //+ ' Fotourl:' + Pet.PhotoUrls[0];
end;

Board footer

Powered by FluxBB