Graceful way to check connection and catch errors?

What’s the best way to gracefully test if the cluster connection is good and/or gracefully fail when bucket does not exist? Currently, this just results in a 500.

try {
        $connectionString = "couchbase://couchbase";

        $options = new ClusterOptions();
        $options->credentials("admin", "password");
        
        $cluster = new Cluster($connectionString, $options);

        $bucket = $cluster->bucket("test");
        
    } catch (\Couchbase\CouchbaseException $e) {
        return ["success" => false, "message" => "bucket does not exist", "details" => $e];
    }