diff --git a/app/api/streak/route.ts b/app/api/streak/route.ts index 28c28277d..2dfcc7f5c 100644 --- a/app/api/streak/route.ts +++ b/app/api/streak/route.ts @@ -387,6 +387,25 @@ type ParseResult = ReturnType; function buildErrorResponse(error: unknown, parseResult: ParseResult): NextResponse { const message = error instanceof Error ? error.message : String(error); + function buildInlineErrorSVG(text: string): string { + const MAX_LINE = 48; + const truncated = text.length > MAX_LINE * 2 ? text.slice(0, MAX_LINE * 2 - 1) + '…' : text; + + const line1 = escapeSVGText(truncated.slice(0, MAX_LINE)); + const line2 = truncated.length > MAX_LINE ? escapeSVGText(truncated.slice(MAX_LINE)) : null; + + const textY = line2 ? '62' : '75'; + + return ` + + ${line1}${ + line2 + ? ` + ${line2}` + : '' + } + `; + } const isNotFound = message.toLowerCase().includes('not found') || @@ -449,14 +468,7 @@ function buildErrorResponse(error: unknown, parseResult: ParseResult): NextRespo // 3. Return a 400 Bad Request for Validation Errors if (isValidationError) { - const validationSvg = ` - - - - ${escapeSVGText(message)} - - - `; + const validationSvg = buildInlineErrorSVG(message); return new NextResponse(validationSvg, { status: 400, @@ -471,14 +483,7 @@ function buildErrorResponse(error: unknown, parseResult: ParseResult): NextRespo // 4. Return a 500 Internal Server Error for real crashes console.error('[streak] Unhandled error:', message); - const errorSvg = ` - - - - Something went wrong. Please try again later. - - - `; + const errorSvg = buildInlineErrorSVG('Something went wrong. Please try again later.'); return new NextResponse(errorSvg, { status: 500,