mirror of
https://github.com/MetaProvide/talked-client.git
synced 2025-04-07 14:15:41 +00:00
Switch to using single quotes and handle issue with json decoding curl response, as json is only available when request is succesful
This commit is contained in:
parent
2aa6edf376
commit
3755f61908
1 changed files with 11 additions and 11 deletions
|
@ -73,7 +73,7 @@ class Record extends Command
|
|||
$serverUrl = $this->config->getAppValue('talked', 'server_url', '');
|
||||
|
||||
if ($serverUrl === '') {
|
||||
$output->writeln("A recording server hasn't been configured yet.");
|
||||
$output->writeln('A recording server hasn\'t been configured yet.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ class Record extends Command
|
|||
return 0;
|
||||
}
|
||||
|
||||
$output->writeln('Nothing to do.');
|
||||
$output->writeln('The specified command doesn\'t exist.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -131,21 +131,21 @@ class Record extends Command
|
|||
}
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $serverUrl . "/" . $endpoint);
|
||||
curl_setopt($ch, CURLOPT_URL, $serverUrl . '/' . $endpoint);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
$result = json_decode(curl_exec($ch));
|
||||
$result = curl_exec($ch);
|
||||
$curl_error_code = curl_errno($ch);
|
||||
$curl_error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($curl_error_code > 0) {
|
||||
$this->logger->error("cURL Error ($curl_error_code): $curl_error");
|
||||
$message = "An error occured while running the command. Please try again or contact an administrator.";
|
||||
$this->logger->error('cURL Error (' . $curl_error_code . '): ' . $curl_error);
|
||||
$message = 'An error occured while running the command. Please try again or contact an administrator.';
|
||||
} else {
|
||||
$message = $result->message;
|
||||
$message = json_decode($result)->message;
|
||||
}
|
||||
|
||||
return $message;
|
||||
|
@ -166,16 +166,16 @@ class Record extends Command
|
|||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
$result = json_decode(curl_exec($ch));
|
||||
$result = curl_exec($ch);
|
||||
$curl_error_code = curl_errno($ch);
|
||||
$curl_error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($curl_error_code > 0) {
|
||||
$this->logger->error("cURL Error ($curl_error_code): $curl_error");
|
||||
$message = "An error occured while running the command. Please try again or contact an administrator.";
|
||||
$this->logger->error('cURL Error (' . $curl_error_code . '): ' . $curl_error);
|
||||
$message = 'An error occured while running the command. Please try again or contact an administrator.';
|
||||
} else {
|
||||
$message = $result->message;
|
||||
$message = json_decode($result)->message;
|
||||
}
|
||||
|
||||
return $message;
|
||||
|
|
Loading…
Add table
Reference in a new issue