ajuste de integração com hawk

This commit is contained in:
Renan Bernordi 2024-12-19 23:28:22 -03:00
parent b4712928e6
commit 425c5aa151
2 changed files with 11 additions and 14 deletions

View file

@ -11,12 +11,10 @@ class Logger
private function __construct() private function __construct()
{ {
// Inicializa o Hawk apenas se houver um token configurado // Inicializa o Hawk
if (!empty(HAWK_TOKEN)) { Catcher::init([
Catcher::init([ 'integrationToken' => HAWK_TOKEN,
'integrationToken' => HAWK_TOKEN, ]);
]);
}
} }
public static function getInstance(): Logger public static function getInstance(): Logger
@ -36,11 +34,6 @@ class Logger
*/ */
public function error(string $message, array $context = [], string $type = 'WARNING'): void public function error(string $message, array $context = [], string $type = 'WARNING'): void
{ {
// Se não houver token do Hawk configurado, não gera log
if (empty(HAWK_TOKEN)) {
return;
}
// Registra no Hawk // Registra no Hawk
try { try {
Catcher::get()->sendException(new Exception($message), [ Catcher::get()->sendException(new Exception($message), [
@ -63,6 +56,11 @@ class Logger
*/ */
public function log(string $url, string $error_group, string $message_error = '', string $type = 'WARNING'): void public function log(string $url, string $error_group, string $message_error = '', string $type = 'WARNING'): void
{ {
// Se não houver token do Hawk configurado, não gera log
if (empty(HAWK_TOKEN)) {
return;
}
$this->error($error_group, [ $this->error($error_group, [
'url' => $url, 'url' => $url,
'timestamp' => time(), 'timestamp' => time(),

View file

@ -115,9 +115,8 @@ class URLAnalyzer
$host = preg_replace('/^www\./', '', $host); $host = preg_replace('/^www\./', '', $host);
if (in_array($host, BLOCKED_DOMAINS)) { if (in_array($host, BLOCKED_DOMAINS)) {
$error = 'BLOCKED_DOMAINS'; Logger::getInstance()->log($cleanUrl, 'BLOCKED_DOMAIN');
Logger::getInstance()->log($cleanUrl, $error); throw new Exception('Este domínio está bloqueado para extração.');
throw new Exception($error);
} }
// 4. Verifica se deve usar Selenium // 4. Verifica se deve usar Selenium