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

38 lines
1.0 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
{
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()]);
}
}
}