/**
  * @param \Exception $e
  *
  * @return \Exception
  */
 public function reconnectIfNeeded(\Exception $e)
 {
     // presumably, any exception caught here is related to some connection error
     if (!$this->ping()) {
         // if pinging fails, we try to reconnect
         try {
             $this->manager->closeConnection($this->getConnection());
             $this->getConnection()->connect();
         } catch (\Exception $e) {
             // if reconnecting fails, there is no way that the bus can continue to function
             return new CriticalErrorException("Database connection failed.", 0, $e);
         }
     }
     return $e;
 }