Files
sam-api/app/Exceptions/Handler.php

41 lines
1.1 KiB
PHP
Raw Normal View History

<?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
{
2025-07-25 09:12:53 +09:00
if (
app()->environment('local') || app()->environment('production')
|| app()->environment('LOCAL') || app()->environment('DEV')
) {
$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, [
2025-07-25 09:12:53 +09:00
'text' => "*🚨[".env('APP_ENV')."] Laravel 예외 발생!*\n" .
"• 메시지: `{$e->getMessage()}`\n" .
"• 위치: `{$e->getFile()}:{$e->getLine()}`\n" .
"• 시간: " . now()->toDateTimeString()
]);
} catch (Throwable $ex) {
logger()->error('슬랙 전송 실패', ['message' => $ex->getMessage()]);
}
}
}