diff --git a/app/bootstrap.php b/app/bootstrap.php index 36b12fd..89c532f 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -68,6 +68,7 @@ public function __construct($plugin, $debug = FALSE) public function addEventQueue(array $event) { $this->_eventQueue[] = $event; + $this->log('Event added to queue: '.json_encode($event)); } /** @@ -79,7 +80,12 @@ public function runEventQueue() { foreach ($this->_eventQueue as $event) { [$eventMethod, $param] = $event; - $this->_pluginInstance->$eventMethod($param); + try { + $this->_pluginInstance->$eventMethod($param); + $this->log('Event processed successfully: '.$eventMethod); + } catch (Throwable $e) { + $this->log('Error processing event '.$eventMethod.': '.$e->getMessage()); + } } } @@ -113,7 +119,7 @@ public function hasConnection() */ public function diagnostics() { - return $this->_pluginInstance->connectionDiagnostics(); + return $this->_pluginInstance->connectionDiagnostics(TRUE); } /** diff --git a/pub/callback.php b/pub/callback.php index f05550b..a03f002 100644 --- a/pub/callback.php +++ b/pub/callback.php @@ -40,7 +40,7 @@ if (empty($middleware)) { error_log($e->getMessage()); } else { - $middleware->log("{$e->getCode()} {$e->getMessage()}"); + $middleware->logException($e); } http_response_code($e->getCode() ?: 500); } diff --git a/pub/oauth.php b/pub/oauth.php index 11de0ec..b09fcd8 100644 --- a/pub/oauth.php +++ b/pub/oauth.php @@ -45,12 +45,10 @@ echo $middleware->renderPage('oauth_status.phtml'); } catch (Exception $e) { - if ($debug) { - if (empty($middleware)) { - error_log($e->getMessage()); - } else { - $middleware->log("{$e->getCode()} {$e->getMessage()}"); - } + if (empty($middleware)) { + error_log($e->getMessage()); + } else { + $middleware->logException($e); } echo $e->getMessage(); } \ No newline at end of file diff --git a/pub/respond.php b/pub/respond.php index 4758fb0..6898c47 100644 --- a/pub/respond.php +++ b/pub/respond.php @@ -43,12 +43,10 @@ $middleware->log(sprintf('Received webhook for %s topic with message: %s', $topic, $json), 'webhooks.log'); $middleware->respond($topic, $message); } catch (Exception $e) { - if ($debug) { - if (empty($middleware)) { - error_log($e->getMessage()); - } else { - $middleware->log("{$e->getCode()} {$e->getMessage()}"); - } + if (empty($middleware)) { + error_log($e->getMessage()); + } else { + $middleware->logException($e); } http_response_code($e->getCode() ?: 500); } diff --git a/pub/webhook.php b/pub/webhook.php index db60316..e6edf32 100644 --- a/pub/webhook.php +++ b/pub/webhook.php @@ -29,12 +29,10 @@ $middleware->webhookController($query, $headers, $data); } catch (Exception $e) { - if ($debug) { - if (empty($middleware)) { - error_log($e->getMessage()); - } else { - $middleware->log("{$e->getCode()} {$e->getMessage()}"); - } + if (empty($middleware)) { + error_log($e->getMessage()); + } else { + $middleware->logException($e); } http_response_code($e->getCode() ?: 500); } diff --git a/run.php b/run.php index b1788f8..1838d70 100755 --- a/run.php +++ b/run.php @@ -22,7 +22,7 @@ $debug = TRUE; array_pop($argv); } -if ($argc == 2) { +if ($argc <= 2) { die($usage); }