AsyncMysqlErrorResult::failureType

The type of failure that produced this result.

Description

public function failureType(): string

The type of failure that produced this result.

The string returned will be either 'TimedOut', representing a timeout, or 'Failed', representing the server rejecting the connection or query.

Return Values

  • string - the type of failure, either 'TimedOut' or 'Failed'.

Examples

When an error occurs when establishing a connection or on a query, and you catch the exception that is thrown, you will get an AsyncMysqlErrorResult. And one of the methods on an AsyncMysqlErrorResult is failureType(), which tells you whether the operation was a timeout (via the string TimedOut) or a server rejection of our connection or query (via the string Failed).

<?hh

namespace Hack\UserDocumentation\API\Examples\AsyncMysql\ErrorResult\FailType;

use \Hack\UserDocumentation\API\Examples\AsyncMysql\ConnectionInfo as CI;

async function connect(\AsyncMysqlConnectionPool $pool):
  Awaitable<\AsyncMysqlConnection> {
  return await $pool->connect(
    CI::$host,
    CI::$port,
    CI::$db,
    CI::$user,
    CI::$passwd
  );
}
async function simple_query_error(): Awaitable<int> {
  $pool = new \AsyncMysqlConnectionPool(array());
  $conn = await connect($pool);
  try {
    $result = await $conn->query('SELECT bogus FROM bogus WHERE bogus = 1');
  } catch (\AsyncMysqlQueryException $ex) {
    $qr = $ex->getResult();
    // Actually `AsyncMysqlQueryErrorResult`
    var_dump($qr instanceof \AsyncMysqlErrorResult);
    var_dump($qr->failureType());
    $conn->close();
    return 0;
  }
  $conn->close();
  return $result->numRows();
}

function run(): void {
  $r = \HH\Asio\join(simple_query_error());
  var_dump($r);
}

run();
Output
bool(true)
string(6) "Failed"
int(0)