DigitalOceanPHP / Client

DigitalOcean API v2 client for PHP
MIT License
709 stars 205 forks source link

Untrapped exceptions when using DigitalOceanV2\Exception #158

Closed jimmydburr closed 4 years ago

jimmydburr commented 7 years ago

I'm getting uncaught exception errors, even though I'm using DigitalOceanV2\Exception code like so:

use DigitalOceanV2\Adapter\GuzzleHttpAdapter;
use DigitalOceanV2\DigitalOceanV2;
use DigitalOceanV2\Exception;

snip...

// snapshot droplets
foreach ($activeDroplets as $drplt) {
    $snapTime = date("Y-m-d_H.i.s", time());
    try {
        echo "Taking a snapshot of $drplt->name on $snapTime.\n";
        $logger->addInfo ("Taking a snapshot of $drplt->name on $snapTime.");
        $droplet->snapshot($drplt->id, 'ss_' . $drplt->name . "_" . $snapTime);
    } catch (Exception $e) {
        echo "Had a problem taking snapshot of $drplt->name. Error: $e->getMessage()";
        $logger->addError ("Had a problem taking snapshot of $drplt->name. Error: $e->getMessage()");
    }
}

The exception is:

PHP Fatal error:  Uncaught exception 'DigitalOceanV2\Exception\HttpException' with message 'there are currently blocking events processing for one or more of the droplets' in /root/do-admin/dosnap/vendor/toin0u/digitalocean-v2/src/Adapter/GuzzleHttpAdapter.php:138
Stack trace:
#0 /root/do-admin/dosnap/vendor/toin0u/digitalocean-v2/src/Adapter/GuzzleHttpAdapter.php(106): DigitalOceanV2\Adapter\GuzzleHttpAdapter->handleError()
#1 /root/do-admin/dosnap/vendor/toin0u/digitalocean-v2/src/Api/Droplet.php(465): DigitalOceanV2\Adapter\GuzzleHttpAdapter->post('https://api.dig...', Array)
#2 /root/do-admin/dosnap/vendor/toin0u/digitalocean-v2/src/Api/Droplet.php(452): DigitalOceanV2\Api\Droplet->executeAction(2471065, Array)
#3 /root/do-admin/dosnap/dosnap.php(84): DigitalOceanV2\Api\Droplet->snapshot(2471065, 'ss_htaSites01_2...')
#4 {main}
 thrown in /root/do-admin/dosnap/vendor/toin0u/digitalocean-v2/src/Adapter/GuzzleHttpAdapter.php on line 138

I guess I'm confused. Should I be using Guzzle's exception handling or don't these "bubble up" through the api's exception handling?

Thanks,

Jim...

samuelfac commented 7 years ago

I have the same issue, when I try to use takeDropletSnapshot" of DigitalApiClient JAVA - 2.8. Java 7.

Stack:

com.myjeeva.digitalocean.exception.DigitalOceanException: there are currently blocking events processing for one or more of the droplets
    at com.myjeeva.digitalocean.impl.DigitalOceanClient.evaluateResponse(DigitalOceanClient.java:1399)
    at com.myjeeva.digitalocean.impl.DigitalOceanClient.executeHttpRequest(DigitalOceanClient.java:1344)
    at com.myjeeva.digitalocean.impl.DigitalOceanClient.doPost(DigitalOceanClient.java:1306)
    at com.myjeeva.digitalocean.impl.DigitalOceanClient.perform(DigitalOceanClient.java:1263)
    at com.myjeeva.digitalocean.impl.DigitalOceanClient.takeDropletSnapshot(DigitalOceanClient.java:438)
GrahamCampbell commented 7 years ago

I have the same issue, when I try to use takeDropletSnapshot" of DigitalApiClient JAVA - 2.8.

That issue is unrelated. The exception is totally correct, that is not the bug here. The issue here was reporting the exception hierarchy.

samuelfac commented 7 years ago

Sorry and Tks.