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, [ 'text' => "*[Laravel] 예외 발생!*\n" . "• 메시지: `{$e->getMessage()}`\n" . "• 위치: `{$e->getFile()}:{$e->getLine()}`\n" . "• 시간: " . now()->toDateTimeString() ]); } catch (Throwable $ex) { logger()->error('슬랙 전송 실패', ['message' => $ex->getMessage()]); } } public function render($request, Throwable $exception) { if ($request->expectsJson()) { // 400 Bad Request (예: ValidationException) if ( $exception instanceof ValidationException || $exception instanceof BadRequestHttpException ) { return response()->json([ 'success' => false, 'message' => '필수 파라미터 누락', 'data' => null, ], 400); } // 401 Unauthorized if ($exception instanceof AuthenticationException) { return response()->json([ 'success' => false, 'message' => '인증 실패', 'data' => null, ], 401); } // 403 Forbidden if ($exception instanceof AccessDeniedHttpException) { return response()->json([ 'success' => false, 'message' => '권한 없음', 'data' => null, ], 403); } // 404 Not Found if ($exception instanceof NotFoundHttpException) { return response()->json([ 'success' => false, 'message' => '존재하지 않는 URI 또는 데이터', 'data' => null, ], 404); } // 405 Method Not Allowed if ($exception instanceof MethodNotAllowedHttpException) { return response()->json([ 'success' => false, 'message' => '허용되지 않는 메서드', 'data' => null, ], 405); } // 500 Internal Server Error (기타 모든 에러) if ( $exception instanceof HttpException && $exception->getStatusCode() === 500 ) { return response()->json([ 'success' => false, 'message' => '서버 에러', 'data' => null, ], 500); } // 그 외 모든 예외 return response()->json([ 'success' => false, 'message' => '서버 에러', 'data' => null, ], 500); } return parent::render($request, $exception); } }