fix: adding comprehensive logs for live server (#7947)
* fix: adding comprehensive logs * fix: document controller naming convention * fix: axios interception logger
This commit is contained in:
parent
9ce6179421
commit
8cd29c5009
10 changed files with 112 additions and 72 deletions
|
|
@ -22,11 +22,11 @@ export class CollaborationController {
|
|||
|
||||
// Set up error handling for the connection
|
||||
ws.on("error", (error: Error) => {
|
||||
logger.error("WebSocket connection error:", error);
|
||||
logger.error("COLLABORATION_CONTROLLER: WebSocket connection error:", error);
|
||||
ws.close(1011, "Internal server error");
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error("WebSocket connection error:", error);
|
||||
logger.error("COLLABORATION_CONTROLLER: WebSocket connection error:", error);
|
||||
ws.close(1011, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
import type { Request, Response } from "express";
|
||||
// plane imports
|
||||
import { Controller, Post } from "@plane/decorators";
|
||||
import { logger } from "@plane/logger";
|
||||
// types
|
||||
import type { TConvertDocumentRequestBody } from "@/types";
|
||||
// utils
|
||||
import { convertHTMLDocumentToAllFormats } from "@/utils";
|
||||
|
||||
@Controller("/convert-document")
|
||||
export class ConvertDocumentController {
|
||||
@Post("/")
|
||||
handleConvertDocument(req: Request, res: Response) {
|
||||
const { description_html, variant } = req.body as TConvertDocumentRequestBody;
|
||||
try {
|
||||
if (typeof description_html !== "string" || variant === undefined) {
|
||||
res.status(400).json({
|
||||
message: "Missing required fields",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const { description, description_binary } = convertHTMLDocumentToAllFormats({
|
||||
document_html: description_html,
|
||||
variant,
|
||||
});
|
||||
res.status(200).json({
|
||||
description,
|
||||
description_binary,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error("Error in /convert-document endpoint:", error);
|
||||
res.status(500).json({
|
||||
message: `Internal server error.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
63
apps/live/src/controllers/document.controller.ts
Normal file
63
apps/live/src/controllers/document.controller.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import type { Request, Response } from "express";
|
||||
import { z } from "zod";
|
||||
// helpers
|
||||
import { Controller, Post } from "@plane/decorators";
|
||||
import { convertHTMLDocumentToAllFormats } from "@plane/editor";
|
||||
// logger
|
||||
import { logger } from "@plane/logger";
|
||||
import { type TConvertDocumentRequestBody } from "@/types";
|
||||
|
||||
// Define the schema with more robust validation
|
||||
const convertDocumentSchema = z.object({
|
||||
description_html: z
|
||||
.string()
|
||||
.min(1, "HTML content cannot be empty")
|
||||
.refine((html) => html.trim().length > 0, "HTML content cannot be just whitespace")
|
||||
.refine((html) => html.includes("<") && html.includes(">"), "Content must be valid HTML"),
|
||||
variant: z.enum(["rich", "document"]),
|
||||
});
|
||||
|
||||
@Controller("/convert-document")
|
||||
export class DocumentController {
|
||||
@Post("/")
|
||||
async convertDocument(req: Request, res: Response) {
|
||||
try {
|
||||
// Validate request body
|
||||
const validatedData = convertDocumentSchema.parse(req.body as TConvertDocumentRequestBody);
|
||||
const { description_html, variant } = validatedData;
|
||||
|
||||
// Process document conversion
|
||||
const { description, description_binary } = convertHTMLDocumentToAllFormats({
|
||||
document_html: description_html,
|
||||
variant,
|
||||
});
|
||||
|
||||
// Return successful response
|
||||
res.status(200).json({
|
||||
description,
|
||||
description_binary,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
const validationErrors = error.errors.map((err) => ({
|
||||
path: err.path.join("."),
|
||||
message: err.message,
|
||||
}));
|
||||
logger.error("DOCUMENT_CONTROLLER: Validation error", {
|
||||
validationErrors,
|
||||
});
|
||||
return res.status(400).json({
|
||||
message: `Validation error`,
|
||||
context: {
|
||||
validationErrors,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
logger.error("DOCUMENT_CONTROLLER: Internal server error", error);
|
||||
return res.status(500).json({
|
||||
message: `Internal server error.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { CollaborationController } from "./collaboration.controller";
|
||||
import { ConvertDocumentController } from "./convert-document.controller";
|
||||
import { DocumentController } from "./document.controller";
|
||||
import { HealthController } from "./health.controller";
|
||||
|
||||
export const CONTROLLERS = [CollaborationController, ConvertDocumentController, HealthController];
|
||||
export const CONTROLLERS = [CollaborationController, DocumentController, HealthController];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue