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:
stirling-image
2026-04-06 21:00:29 +08:00
committed by GitHub
co-authored by Siddharth Kumar Sah
parent 9e9a22cdd1
commit 75c7f135fe
5 changed files with 35 additions and 0 deletions
+5
View File
@@ -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",