This commit is contained in:
Dave M. 2023-11-03 20:03:49 -04:00
commit a552a6675e
6 changed files with 16 additions and 10 deletions

View File

@ -22,7 +22,7 @@ namespace Negundo\Client {
static::$instances[] = $this;
}
public function pushData(...$content) : ? object
public function pushData(...$content) : object|null|bool
{
$data = $this->dumpHandler->dumpData(...$content);

View File

@ -55,7 +55,7 @@ abstract class Handler {
});
}
public function pushData(\Throwable $ex) : ? object
public function pushData(\Throwable $ex) : null|object|bool
{
// Make sure not to spam the server if an ErrorMessage or Exception was already sent (like inside a loop)
$exceptionHash = $this->exceptionHandler->hash($ex);

View File

@ -25,7 +25,7 @@ namespace Negundo\Client {
static::$instances[] = $this;
}
public function newReport(string $message, ? string $title = null, ? array $data = []) : ? object
public function newReport(string $message, ? string $title = null, ? array $data = []) : object|null|bool
{
$report = $this->taskHandler->sendReport($message, $title, $data);
@ -45,9 +45,13 @@ namespace Negundo\Client {
namespace {
if (! function_exists('ntask') ) {
function ntask(string $message, ? string $title = null, ? array $data) {
function ntask(string $message, ? string $title = null, ? array $data = null) {
foreach (\Negundo\Client\Task::$instances as $instance) {
$instance->newReport($message, $title, $data);
$sent = $instance->newReport($message, $title, $data);
if (! $sent ) {
throw new \Exception(sprintf('Could not send report titled `%s`.', $title));
}
}
}
}

View File

@ -10,7 +10,7 @@ class Curl implements TransportInterface {
public $headers = [];
public function push(string $url, array $data) : ? object
public function push(string $url, array $data) : object|null|bool
{
$ch = curl_init();
@ -22,7 +22,9 @@ class Curl implements TransportInterface {
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout * 200);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if ( ( false === curl_exec($ch) ) && $this->throwErrors ) {
$exec = curl_exec($ch);
if ( ( false === $exec ) && $this->throwErrors ) {
$errno = curl_errno($ch);
$errors = array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ]);
@ -31,7 +33,7 @@ class Curl implements TransportInterface {
curl_close($ch);
return null;
return $exec;
}
const CURL_ERROR = [

View File

@ -12,7 +12,7 @@ class GuzzleClient implements TransportInterface {
public array $headers = [];
public function push(string $url, array $data) : ? object
public function push(string $url, array $data) : object|null|bool
{
return ( new Client([
'timeout' => $this->timeout,

View File

@ -3,5 +3,5 @@
namespace Negundo\Client\Transport;
interface TransportInterface {
public function push(string $url, array $data) : ? object;
public function push(string $url, array $data) : object|null|bool;
}