Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

Fix e2e handling for index url 404 not found error (#234)

Hari John Kuriakosed403623681c8
diff --git a/backend/middleware/exception.py b/backend/middleware/exception.py
index a03ac6872..1bb9e91e3 100644
--- a/backend/middleware/exception.py
+++ b/backend/middleware/exception.py
@@ -11,6 +11,7 @@ from rest_framework.response import Response
logger = logging.getLogger(__name__)
+# Set via settings.REST_FRAMEWORK.EXCEPTION_HANDLER.
def drf_logging_exc_handler(exc: Exception, context: Any) -> Optional[Response]:
"""Custom exception handler for DRF.
@@ -29,10 +30,11 @@ def drf_logging_exc_handler(exc: Exception, context: Any) -> Optional[Response]:
handled by another method in the middleware
"""
request = context.get("request")
+ response = exception_handler(exc=exc, context=context)
ExceptionLoggingMiddleware.format_exc_and_log(
- request=request, exception=exc
+ request=request, response=response, exception=exc
)
- return exception_handler(exc=exc, context=context)
+ return response
class ExceptionLoggingMiddleware:
@@ -70,16 +72,30 @@ class ExceptionLoggingMiddleware:
return None
@staticmethod
- def format_exc_and_log(request: HttpRequest, exception: Exception) -> None:
+ def format_exc_and_log(
+ request: HttpRequest, response: HttpResponse, exception: Exception
+ ) -> None:
"""Format the exception to be logged and logs it.
Args:
request (HttpRequest): Request to get API endpoint hit
exception (Exception): Exception that was raised to be logged
"""
- message = "**{url}**\n\n{error}\n\n````{tb}````".format(
- url=request.build_absolute_uri(),
- error=repr(exception),
- tb=traceback.format_exc(),
- )
+ if response.status_code >= 500:
+ message = (
+ "{method} {url} {status}\n\n{error}\n\n````{tb}````".format(
+ method=request.method,
+ url=request.build_absolute_uri(),
+ status=response.status_code,
+ error=repr(exception),
+ tb=traceback.format_exc(),
+ )
+ )
+ else:
+ message = "{method} {url} {status} {error}".format(
+ method=request.method,
+ url=request.build_absolute_uri(),
+ status=response.status_code,
+ error=repr(exception),
+ )
logger.error(message)
diff --git a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py
index e2ad5f859..148017e6d 100644
--- a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py
+++ b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py
@@ -618,13 +618,20 @@ class PromptStudioHelper:
util = PromptIdeBaseTool(log_level=LogLevel.INFO, org_id=org_id)
tool_index = ToolIndex(tool=util)
except Exception as e:
- logger.error(f"Error while instatiating SDKs {e}")
- raise IndexingAPIError()
+ PromptStudioHelper._publish_log(
+ {"tool_id": tool_id, "doc_name": os.path.split(file_path)[1]},
+ LogLevels.ERROR,
+ LogLevels.RUN,
+ "Indexing failed",
+ )
+ raise IndexingAPIError(str(e)) from e
+
embedding_model = str(profile_manager.embedding_model.id)
vector_db = str(profile_manager.vector_store.id)
x2text_adapter = str(profile_manager.x2text.id)
file_hash = ToolUtils.get_hash_from_file(file_path=file_path)
extract_file_path: Optional[str] = None
+
if not is_summary:
directory, filename = os.path.split(file_path)
extract_file_path = os.path.join(
@@ -632,6 +639,7 @@ class PromptStudioHelper:
)
else:
profile_manager.chunk_size = 0
+
try:
doc_id: str = tool_index.index_file(
tool_id=tool_id,
@@ -654,6 +662,12 @@ class PromptStudioHelper:
)
return doc_id
except IndexingError as e:
+ PromptStudioHelper._publish_log(
+ {"tool_id": tool_id, "doc_name": os.path.split(file_path)[1]},
+ LogLevels.ERROR,
+ LogLevels.RUN,
+ "Indexing failed",
+ )
raise IndexingAPIError(str(e)) from e
@staticmethod
diff --git a/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsx b/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsx
index 2c65029ec..a2929d9a6 100644
--- a/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsx
+++ b/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsx
@@ -21,16 +21,16 @@ import PropTypes from "prop-types";
import { useEffect, useState } from "react";
import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";
+import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
import { useAlertStore } from "../../../store/alert-store";
import { useCustomToolStore } from "../../../store/custom-tool-store";
import { useSessionStore } from "../../../store/session-store";
+import { useSocketCustomToolStore } from "../../../store/socket-custom-tool";
import { ConfirmModal } from "../../widgets/confirm-modal/ConfirmModal";
import { EmptyState } from "../../widgets/empty-state/EmptyState";
import SpaceWrapper from "../../widgets/space-wrapper/SpaceWrapper";
-import "./ManageDocsModal.css";
-import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
import { SpinnerLoader } from "../../widgets/spinner-loader/SpinnerLoader";
-import { useSocketCustomToolStore } from "../../../store/socket-custom-tool";
+import "./ManageDocsModal.css";
let SummarizeStatusTitle = null;
try {
@@ -99,11 +99,11 @@ function ManageDocsModal({
const infoIndex = (indexMessage) => {
let color = "default";
+
if (indexMessage?.level === "INFO") {
color = "processing";
}
-
- if (indexMessage?.length === "ERROR") {
+ if (indexMessage?.level === "ERROR") {
color = "error";
}