Как устранить неполадки / получить ответ об ошибке при запуске недопустимых заданий BigQuery?
В этом коде я пытаюсь запустить выбор для таблицы, которая не существует,getJobReference()
возвращаетсяNULL
и я хотел бы поймать такого рода ошибки, и хотел бы получить сообщения об ошибках, полученные каким-либо образом.
Как получить сообщение об ошибке при сбое?
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
//$client->setDeveloperKey(API_KEY);
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name, array(
'https://www.googleapis.com/auth/bigquery',
), $key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
var_dump($_SESSION);
$bq = new Google_Service_Bigquery($client);
//build query
$sql = 'select * from example.table LIMIT 10';
$job = new Google_Service_Bigquery_Job();
$config = new Google_Service_Bigquery_JobConfiguration();
$queryConfig = new Google_Service_Bigquery_JobConfigurationQuery();
$config->setQuery($queryConfig);
$job->setConfiguration($config);
$queryConfig->setQuery($sql);
$insert = new Google_Service_Bigquery_Job($bq->jobs->insert(PROJECT_ID, $job));
$jr = $insert->getJobReference();
var_dump($jr);/*THIS RETURNS NULL */
$jobId = $jr['jobId'];
$res = new Google_Service_Bigquery_GetQueryResultsResponse($bq->jobs->getQueryResults(PROJECT_ID, $jobId));
//see the results made it as an object ok:
var_dump($res);