mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: add server-side logging to AI tool routes (#23)
AI routes (remove-background, erase-object, ocr, blur-faces, upscale) were silently swallowing errors - failures returned HTTP 422 to the client but never appeared in server logs. This made it impossible for self-hosters to diagnose issues like 504 timeouts from reverse proxies. Adds request.log.info() at processing start (tool name, image size, key settings) and request.log.error() in catch blocks, matching the existing tool-factory pattern. Co-authored-by: Siddharth Kumar Sah <siddharth123sk@gmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Siddharth Kumar Sah
parent
9e9a22cdd1
commit
75c7f135fe
@@ -55,6 +55,15 @@ export function registerBlurFaces(app: FastifyInstance) {
|
||||
|
||||
try {
|
||||
const settings = settingsRaw ? JSON.parse(settingsRaw) : {};
|
||||
request.log.info(
|
||||
{
|
||||
toolId: "blur-faces",
|
||||
imageSize: fileBuffer.length,
|
||||
blurRadius: settings.blurRadius,
|
||||
sensitivity: settings.sensitivity,
|
||||
},
|
||||
"Starting face blur",
|
||||
);
|
||||
|
||||
// Auto-orient to fix EXIF rotation before face detection
|
||||
fileBuffer = await autoOrient(fileBuffer);
|
||||
@@ -111,6 +120,7 @@ export function registerBlurFaces(app: FastifyInstance) {
|
||||
faces: result.faces,
|
||||
});
|
||||
} catch (err) {
|
||||
request.log.error({ err, toolId: "blur-faces" }, "Face blur failed");
|
||||
return reply.status(422).send({
|
||||
error: "Face blur failed",
|
||||
details: err instanceof Error ? err.message : "Unknown error",
|
||||
|
||||
@@ -63,6 +63,10 @@ export function registerEraseObject(app: FastifyInstance) {
|
||||
}
|
||||
|
||||
try {
|
||||
request.log.info(
|
||||
{ toolId: "erase-object", imageSize: imageBuffer.length, maskSize: maskBuffer.length },
|
||||
"Starting object erasure",
|
||||
);
|
||||
const jobId = randomUUID();
|
||||
const workspacePath = await createWorkspace(jobId);
|
||||
|
||||
@@ -110,6 +114,7 @@ export function registerEraseObject(app: FastifyInstance) {
|
||||
processedSize: resultBuffer.length,
|
||||
});
|
||||
} catch (err) {
|
||||
request.log.error({ err, toolId: "erase-object" }, "Object erasing failed");
|
||||
return reply.status(422).send({
|
||||
error: "Object erasing failed",
|
||||
details: err instanceof Error ? err.message : "Unknown error",
|
||||
|
||||
@@ -70,6 +70,15 @@ export function registerOcr(app: FastifyInstance) {
|
||||
return reply.status(400).send({ error: "Settings must be valid JSON" });
|
||||
}
|
||||
|
||||
request.log.info(
|
||||
{
|
||||
toolId: "ocr",
|
||||
imageSize: fileBuffer.length,
|
||||
engine: settings.engine,
|
||||
language: settings.language,
|
||||
},
|
||||
"Starting OCR",
|
||||
);
|
||||
const jobId = randomUUID();
|
||||
const workspacePath = await createWorkspace(jobId);
|
||||
|
||||
@@ -110,6 +119,7 @@ export function registerOcr(app: FastifyInstance) {
|
||||
engine: result.engine,
|
||||
});
|
||||
} catch (err) {
|
||||
request.log.error({ err, toolId: "ocr" }, "OCR failed");
|
||||
return reply.status(422).send({
|
||||
error: "OCR failed",
|
||||
details: err instanceof Error ? err.message : "Unknown error",
|
||||
|
||||
@@ -56,6 +56,10 @@ export function registerRemoveBackground(app: FastifyInstance) {
|
||||
|
||||
try {
|
||||
const settings = settingsRaw ? JSON.parse(settingsRaw) : {};
|
||||
request.log.info(
|
||||
{ toolId: "remove-background", imageSize: fileBuffer.length, model: settings.model },
|
||||
"Starting background removal",
|
||||
);
|
||||
const jobId = randomUUID();
|
||||
const workspacePath = await createWorkspace(jobId);
|
||||
|
||||
@@ -103,6 +107,7 @@ export function registerRemoveBackground(app: FastifyInstance) {
|
||||
processedSize: resultBuffer.length,
|
||||
});
|
||||
} catch (err) {
|
||||
request.log.error({ err, toolId: "remove-background" }, "Background removal failed");
|
||||
return reply.status(422).send({
|
||||
error: "Background removal failed",
|
||||
details: err instanceof Error ? err.message : "Unknown error",
|
||||
|
||||
@@ -56,6 +56,10 @@ export function registerUpscale(app: FastifyInstance) {
|
||||
try {
|
||||
const settings = settingsRaw ? JSON.parse(settingsRaw) : {};
|
||||
const scale = Number(settings.scale) || 2;
|
||||
request.log.info(
|
||||
{ toolId: "upscale", imageSize: fileBuffer.length, scale },
|
||||
"Starting upscale",
|
||||
);
|
||||
|
||||
// Auto-orient to fix EXIF rotation before upscaling
|
||||
fileBuffer = await autoOrient(fileBuffer);
|
||||
@@ -110,6 +114,7 @@ export function registerUpscale(app: FastifyInstance) {
|
||||
method: result.method,
|
||||
});
|
||||
} catch (err) {
|
||||
request.log.error({ err, toolId: "upscale" }, "Upscaling failed");
|
||||
return reply.status(422).send({
|
||||
error: "Upscaling failed",
|
||||
details: err instanceof Error ? err.message : "Unknown error",
|
||||
|
||||
Reference in New Issue
Block a user