feat : 오류 발생시 슬랙으로 전송

This commit is contained in:
2025-07-24 17:55:20 +09:00
parent d01fda5290
commit 84173d9afb
5 changed files with 59 additions and 182 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use Illuminate\Support\Facades\Http;
class Handler extends ExceptionHandler
{
public function report(Throwable $e): void
{
if (app()->environment('local') || app()->environment('production')) {
$this->sendSlackException($e);
}
parent::report($e); // 로그는 그대로
}
protected function sendSlackException(Throwable $e): void
{
try {
$url = env('LOG_SLACK_WEBHOOK_URL');
if (!$url) return;
Http::post($url, [
'text' => "*🚨 Laravel 예외 발생!*\n" .
"• 메시지: `{$e->getMessage()}`\n" .
"• 위치: `{$e->getFile()}:{$e->getLine()}`\n" .
"• 시간: " . now()->toDateTimeString()
]);
} catch (Throwable $ex) {
logger()->error('슬랙 전송 실패', ['message' => $ex->getMessage()]);
}
}
}