I have php file with html code inside, I have div showing Currency rates from included rates.php file (it gets rates from local National Bank Api), when api has problems (rates.php shows error and doesn't show rates) all the site (code after this php include) breaks, doesn't render, can I somehow prevent it from stopping render?

    <?

 $client = new SoapClient('http://nbg.gov.ge/currency.wsdl');
 print ("Exchange Rates: 1 USD - ");
 print $client->GetCurrency('USD').'₾ |';
 $client2 = new SoapClient('http://nbg.gov.ge/currency.wsdl');
 print (" 1 EUR - ");
 print $client2->GetCurrency('EUR').'₾';

?>

error screenshot

1 Answers

0
RiggsFolly On Best Solutions

Failing to instantiate the Soap Client should throw an Exception so you could try something like this

<?php

try {
    $client = new SoapClient('http://nbg.gov.ge/currency.wsdl');

    print ("Exchange Rates: 1 USD - ");
    print $client->GetCurrency('USD').'₾ |';
    print (" 1 EUR - ");
    print $client->GetCurrency('EUR').'₾';
} catch (Exception $e) {
    echo 'A nice message telling the user that something is wrong, try again in a little while';
    //echo $e->getMessage();
}

PS You dont need 2 instances of SoapClient, one will do nicely.