fix: resolve multi-page PDF crashes and Gemini API ingestion errors (#2781)

* fix: resolve multi-page PDF crashes and Gemini API ingestion errors

* fix type errors

* refactor: address PR review feedback and prevent call stack recursion in regex payload scanner

---------

Co-authored-by: Ofir <ofir@example.com>
Co-authored-by: Amruth Pillai <im.amruth@gmail.com>
This commit is contained in:
obitton
2026-03-16 18:08:40 -04:00
committed by GitHub
parent ea8fd838d9
commit fb61bb4a63
8 changed files with 818 additions and 278 deletions
+18 -4
View File
@@ -2,10 +2,10 @@ import { ORPCError } from "@orpc/client";
import { type } from "@orpc/server";
import { AISDKError, type UIMessage } from "ai";
import { OllamaError } from "ai-sdk-ollama";
import z, { ZodError } from "zod";
import z, { flattenError, ZodError } from "zod";
import type { ResumeData } from "@/schema/resume/data";
import { protectedProcedure } from "../context";
import { aiCredentialsSchema, aiProviderSchema, aiService, fileInputSchema, formatZodError } from "../services/ai";
import { aiCredentialsSchema, aiProviderSchema, aiService, fileInputSchema } from "../services/ai";
type AIProvider = z.infer<typeof aiProviderSchema>;
@@ -69,6 +69,10 @@ export const aiRouter = {
message: "The AI provider returned an error or is unreachable.",
status: 502,
},
BAD_REQUEST: {
message: "The AI returned an improperly formatted structure.",
status: 400,
},
})
.handler(async ({ input }): Promise<ResumeData> => {
try {
@@ -79,7 +83,10 @@ export const aiRouter = {
}
if (error instanceof ZodError) {
throw new Error(formatZodError(error));
throw new ORPCError("BAD_REQUEST", {
message: "Invalid resume data structure",
cause: flattenError(error),
});
}
throw error;
}
@@ -111,6 +118,10 @@ export const aiRouter = {
message: "The AI provider returned an error or is unreachable.",
status: 502,
},
BAD_REQUEST: {
message: "The AI returned an improperly formatted structure.",
status: 400,
},
})
.handler(async ({ input }) => {
try {
@@ -121,7 +132,10 @@ export const aiRouter = {
}
if (error instanceof ZodError) {
throw new Error(formatZodError(error));
throw new ORPCError("BAD_REQUEST", {
message: "Invalid resume data structure",
cause: flattenError(error),
});
}
throw error;