Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exceptions like http/40x #259

Closed
numitec opened this issue Oct 13, 2018 · 1 comment
Closed

Handle exceptions like http/40x #259

numitec opened this issue Oct 13, 2018 · 1 comment

Comments

@numitec
Copy link

numitec commented Oct 13, 2018

Hello there,

is there a way to try/catch exceptions like "404 Not Found" when querying the API?

OpenStack\Common\Error\BadResponseError: HTTP Error
~~~~~~~~~~
The remote server returned a "404 Not Found" error for the following transaction:
[...]

While instancing OpenStack object I have tried to pass argument:

'requestOptions' => [ 'http_errors' => false ],

but doesn't work. Either with a try/catch:

try {
   $server = $compute->getServer(['id' => $this->openstack_id ]);
   $server->retrieve();
}
catch( ClientErrorResponseException $e ) {
   [...]
}

Thank you!

@numitec
Copy link
Author

numitec commented Oct 16, 2018

Resolved with this:

use GuzzleHttp\Exception\ClientErrorResponseException;
...
	try {
		$server = $api->createServer( $options );
		...
	} catch( \Exception $e ) {

		if( $e->getResponse()->getStatusCode() == 403 )
			...
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant