Skip to content

Handle exceptions like http/40x  #259

Description

@numitec

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!

Activity

  1. numitec commented on Oct 16, 2018

    @numitec
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions