dpp1res
dpp1res

Reputation: 1

ERROR: "Parsing WSDL: Couldn't load from" then do something

I have a SoapClient that is falling sometimes.

// send request
$client = new SoapClient("http://XXXXXXXXX.org/NowPlaying.asmx?WSDL");
$result = $client->GetNowPlaying();

// get array of items
$arr = $result->GetNowPlayingResult->PlayerItem;

In those times I would like to show something insted of the Error Message. I have done many if/else statements but anything work.

Can you help me?

Upvotes: 0

Views: 132

Answers (1)

ThePloki
ThePloki

Reputation: 185

Have you tried a try/catch?

try {
    // send request
    $client = new SoapClient("http://XXXXXXXXX.org/NowPlaying.asmx?WSDL");
    $result = $client->GetNowPlaying();

    // get array of items
    $arr = $result->GetNowPlayingResult->PlayerItem;
} catch (Exception $e) {
    echo 'Sorry, there was a problem!<br><br>';
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Upvotes: 1

Related Questions