Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(trpc): enhance error handling for Langfuse Cloud deployments (#9914)

marliessophiec3b5d002bafc
diff --git a/web/src/server/api/trpc.ts b/web/src/server/api/trpc.ts
index 92a62dfda9..5a55873647 100644
--- a/web/src/server/api/trpc.ts
+++ b/web/src/server/api/trpc.ts
@@ -92,9 +92,12 @@ import {
} from "@langfuse/shared/src/server";
import { AdminApiAuthService } from "@/src/ee/features/admin-api/server/adminApiAuth";
+import { env } from "@/src/env.mjs";
setUpSuperjson();
+const isLangfuseCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);
+
const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
@@ -153,13 +156,16 @@ const withErrorHandling = t.middleware(async ({ ctx, next }) => {
// - Either the original error message OR "Internal error" if it's a 5xx error
const httpStatus = getHTTPStatusCodeFromError(res.error);
const isSafeToExpose = httpStatus >= 400 && httpStatus < 500;
+ const errorMessage = isLangfuseCloud
+ ? "We have been notified and are working on it."
+ : "Please check error logs in your self-hosted deployment.";
res.error = new TRPCError({
code: res.error.code,
cause: null, // do not expose stack traces
message: isSafeToExpose
? res.error.message
- : "Internal error. We have been notified and are working on it.",
+ : "Internal error. " + errorMessage,
});
}
}