diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 434d377..83bdeef 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -16,8 +16,38 @@ class Handler extends ExceptionHandler { + /** + * 특정 IP에서 발생하는 예외를 슬랙/로그에서 무시할지 확인 + */ + protected function shouldIgnoreException(Throwable $e): bool + { + $ignoredIps = array_filter( + array_map('trim', explode(',', env('EXCEPTION_IGNORED_IPS', ''))) + ); + + if (empty($ignoredIps)) { + return false; + } + + $currentIp = request()?->ip(); + + // 무시할 IP 목록에 있고, '회원정보 정보 없음' 예외인 경우 + if (in_array($currentIp, $ignoredIps, true)) { + if ($e instanceof AuthenticationException && $e->getMessage() === '회원정보 정보 없음') { + return true; + } + } + + return false; + } + public function report(Throwable $e): void { + // 무시할 예외인 경우 슬랙/로그 모두 건너뜀 + if ($this->shouldIgnoreException($e)) { + return; + } + try { if ( app()->environment('local') || app()->environment('production')