Skip to content

Commit

Permalink
v0.0.33
Browse files Browse the repository at this point in the history
Add monitoring for errors.
  • Loading branch information
ewilan-riviere committed Feb 15, 2024
1 parent ac53a66 commit 3d9ef91
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kiwilan/php-notifier",
"description": "PHP Notifier is a package to send mails or notifications for Discord or Slack.",
"version": "0.0.32",
"version": "0.0.33",
"keywords": [
"notifier",
"slack",
Expand Down
6 changes: 3 additions & 3 deletions src/Discord/DiscordContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function send(bool $mock = false): static
$this->isSuccess = $this->request->getStatusCode() === 204 || $this->request->getStatusCode() === 200;

if ($this->isSuccess) {
// Log::error("Notifier: discord notification failed with HTTP {$this->request->getStatusCode()}", [
// $this->request->toArray(),
// ]);
$this->discord->getLogSent($this->request->toArray());
} else {
$this->discord->getLogError('Discord notification failed with HTTP '.$this->request->getStatusCode(), $this->request->toArray());
}

return $this;
Expand Down
2 changes: 2 additions & 0 deletions src/NotifierDiscord.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function getLogError(string $reason, array $data = []): void
{
if ($this->logError) {
($this->logError)($reason, $data);
} else {
NotifierShared::logError($reason, $data);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/NotifierHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Kiwilan\Notifier\Utils\NotifierHttpClient;
use Kiwilan\Notifier\Utils\NotifierShared;

class NotifierHttp extends Notifier
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public function send(bool $mock = false): self
if ($this->logError) {
$this->getLogError('HTTP '.$statusCode, $this->request->toArray());
} else {
error_log('HTTP '.$statusCode.': '.json_encode($this->request->toArray()));
NotifierShared::logError('HTTP '.$statusCode, $this->request->toArray());
}

return $this;
Expand Down
3 changes: 1 addition & 2 deletions src/NotifierMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ public function send(bool $mock = false): self
if ($this->logError) {
($this->logError)($th->getMessage(), $this->toArray());
} else {
$data = json_encode($this->toArray());
error_log($th->getMessage().': '.$data);
NotifierShared::logError($th->getMessage(), $this->toArray());
}

return $this;
Expand Down
2 changes: 2 additions & 0 deletions src/NotifierSlack.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function getLogError(string $reason, array $data = []): void
{
if ($this->logError) {
($this->logError)($reason, $data);
} else {
NotifierShared::logError($reason, $data);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Utils/NotifierShared.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public static function getShortcutColor(string $color): string
default => '22c55e',
};
}

public static function logError(string $reason, array $data = []): void
{
error_log($reason.PHP_EOL.json_encode($data, JSON_PRETTY_PRINT));
}
}

0 comments on commit 3d9ef91

Please sign in to comment.