Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Add error details to Go Markdown Service (#2624)

Abimael Martellb172bbe4ca1b
diff --git a/apps/api/src/lib/html-to-markdown-client.ts b/apps/api/src/lib/html-to-markdown-client.ts
index a4e9bc263..62e613522 100644
--- a/apps/api/src/lib/html-to-markdown-client.ts
+++ b/apps/api/src/lib/html-to-markdown-client.ts
@@ -22,6 +22,7 @@ interface ConvertResponse {
interface ErrorResponse {
error: string;
+ details?: string;
success: boolean;
}
@@ -83,10 +84,12 @@ export async function convertHTMLToMarkdownWithHttpService(
const errorMessage =
axiosError.response?.data?.error || axiosError.message;
+ const errorDetails = axiosError.response?.data?.details;
const statusCode = axiosError.response?.status;
contextLogger.error("HTML to Markdown conversion failed", {
error: errorMessage,
+ details: errorDetails,
statusCode,
duration_ms: duration,
serviceUrl: url,
@@ -102,11 +105,17 @@ export async function convertHTMLToMarkdownWithHttpService(
extra: {
serviceUrl: url,
errorMessage,
+ errorDetails,
inputSize: html.length,
},
});
- throw new Error(`HTML to Markdown conversion failed: ${errorMessage}`);
+ // Include details in error message if available
+ const fullErrorMessage = errorDetails
+ ? `HTML to Markdown conversion failed: ${errorMessage} - ${errorDetails}`
+ : `HTML to Markdown conversion failed: ${errorMessage}`;
+
+ throw new Error(fullErrorMessage);
} else {
contextLogger.error(
"Unexpected error during HTML to Markdown conversion",
diff --git a/apps/go-html-to-md-service/handler.go b/apps/go-html-to-md-service/handler.go
index 06b650fdb..36556211f 100644
--- a/apps/go-html-to-md-service/handler.go
+++ b/apps/go-html-to-md-service/handler.go
@@ -92,6 +92,7 @@ type ConvertResponse struct {
// ErrorResponse represents an error response
type ErrorResponse struct {
Error string `json:"error"`
+ Details string `json:"details,omitempty"`
Success bool `json:"success"`
}
@@ -106,20 +107,20 @@ func (h *Handler) ConvertHTML(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
log.Error().Err(err).Msg("Failed to read request body")
- h.sendError(w, "Failed to read request body", http.StatusBadRequest)
+ h.sendError(w, "Failed to read request body", err.Error(), http.StatusBadRequest)
return
}
var req ConvertRequest
if err := json.Unmarshal(body, &req); err != nil {
log.Error().Err(err).Msg("Failed to parse request body")
- h.sendError(w, "Invalid JSON in request body", http.StatusBadRequest)
+ h.sendError(w, "Invalid JSON in request body", err.Error(), http.StatusBadRequest)
return
}
// Validate input
if req.HTML == "" {
- h.sendError(w, "HTML field is required", http.StatusBadRequest)
+ h.sendError(w, "HTML field is required", "The 'html' field cannot be empty", http.StatusBadRequest)
return
}
@@ -127,7 +128,7 @@ func (h *Handler) ConvertHTML(w http.ResponseWriter, r *http.Request) {
markdown, err := h.converter.ConvertHTMLToMarkdown(req.HTML)
if err != nil {
log.Error().Err(err).Msg("Failed to convert HTML to Markdown")
- h.sendError(w, "Failed to convert HTML to Markdown", http.StatusInternalServerError)
+ h.sendError(w, "Failed to convert HTML to Markdown", err.Error(), http.StatusInternalServerError)
return
}
@@ -151,9 +152,10 @@ func (h *Handler) ConvertHTML(w http.ResponseWriter, r *http.Request) {
}
// sendError sends an error response
-func (h *Handler) sendError(w http.ResponseWriter, message string, statusCode int) {
+func (h *Handler) sendError(w http.ResponseWriter, message string, details string, statusCode int) {
response := ErrorResponse{
Error: message,
+ Details: details,
Success: false,
}
@@ -161,4 +163,3 @@ func (h *Handler) sendError(w http.ResponseWriter, message string, statusCode in
w.WriteHeader(statusCode)
json.NewEncoder(w).Encode(response)
}
-