You are not logged in.
Pages: 1
Thank you for the quick adjustment.
The generated method Client.GetPetById(PetId) does not throw errors even if the ID does not exist, so the except block can never be reached.
In my case it seems, that the exception does not work. Maybe because TPet is a record.
What do you think about this implementation?
function TCustomPetStoreClient.GetPetByID(PetID: Integer; var ResultPet: TPet): Boolean;
begin
fClient.Request('GET', '/api/pet/%', [PetId], [], [], ResultPet, TypeInfo(TPet));
Result := fClient.Http.Status = 200;
end;
It works. But isn't there a better solution?
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;
Pages: 1