🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): return 4xx for rejected billing, prompt list and media storage inputs (#18579)
Niklas Semmlerf0172709e700
diff --git a/web/src/__tests__/server/prompts-trpc.servertest.ts b/web/src/__tests__/server/prompts-trpc.servertest.tsindex a67cb0495c..d120cffad3 100644--- a/web/src/__tests__/server/prompts-trpc.servertest.ts+++ b/web/src/__tests__/server/prompts-trpc.servertest.ts@@ -178,6 +178,20 @@ describe("prompts trpc", () => {}),).resolves.toMatchObject({ prompts: [], totalCount: 0 });});++ it("lists prompts when orderBy is null", async () => {+ const { project, caller } = await prepare();++ await expect(+ caller.prompts.all({+ projectId: project.id,+ page: 0,+ limit: 10,+ filter: [],+ orderBy: null,+ }),+ ).resolves.toMatchObject({ prompts: [], totalCount: 0 });+ });});describe("prompts.importBulk", () => {diff --git a/web/src/__tests__/server/unit/stripeBillingService.servertest.ts b/web/src/__tests__/server/unit/stripeBillingService.servertest.tsindex 6a6b7f457b..ab9f90fd10 100644--- a/web/src/__tests__/server/unit/stripeBillingService.servertest.ts+++ b/web/src/__tests__/server/unit/stripeBillingService.servertest.ts@@ -70,7 +70,7 @@ describe("stripeBillingService", () => {vi.resetAllMocks();});- describe("cancel, reactivate and clear without an active subscription", () => {+ describe("operations without an active subscription", () => {it.each([["cancel", (s: BillingService) => s.cancel(ORG_ID)],["reactivate", (s: BillingService) => s.reactivate(ORG_ID)],@@ -78,6 +78,18 @@ describe("stripeBillingService", () => {"clearPlanSwitchSchedule",(s: BillingService) => s.clearPlanSwitchSchedule(ORG_ID),],+ [+ "changePlan",+ (s: BillingService) => s.changePlan(ORG_ID, "prod_unknown"),+ ],+ [+ "getCustomerPortalUrl",+ (s: BillingService) => s.getCustomerPortalUrl(ORG_ID),+ ],+ [+ "applyPromotionCode",+ (s: BillingService) => s.applyPromotionCode(ORG_ID, "PROMO"),+ ],])("maps %s onto PRECONDITION_FAILED and does not call Stripe",async (_label, call) => {@@ -93,4 +105,12 @@ describe("stripeBillingService", () => {},);});++ it("rejects checkout for an unknown product with BAD_REQUEST", async () => {+ findUnique.mockResolvedValue(stubOrg(null));++ expect(+ await trpcCode(service().createCheckoutSession(ORG_ID, "prod_unknown")),+ ).toBe("BAD_REQUEST");+ });});diff --git a/web/src/ee/features/billing/server/stripe/stripeBillingService.ts b/web/src/ee/features/billing/server/stripe/stripeBillingService.tsindex 27c983d84e..1cffa0fdb8 100644--- a/web/src/ee/features/billing/server/stripe/stripeBillingService.ts+++ b/web/src/ee/features/billing/server/stripe/stripeBillingService.ts@@ -568,7 +568,7 @@ export class BillingService {if (!stripeCustomerId || !stripeSubscriptionId) {throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "PRECONDITION_FAILED",message: "No stripe customer or subscription found",});}@@ -637,7 +637,7 @@ export class BillingService {if (parsedOrg.cloudConfig?.plan) {throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "PRECONDITION_FAILED",message:"Cannot initialize stripe checkout for orgs that have a manual plan override",});@@ -645,7 +645,7 @@ export class BillingService {if (!StripeCatalogue.isValidCheckoutProduct(stripeProductId)) {throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "BAD_REQUEST",message: "Invalid stripe product id",});}@@ -796,7 +796,7 @@ export class BillingService {if (parsedOrg.cloudConfig?.plan)throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "PRECONDITION_FAILED",message:"Cannot change plan for orgs that have a manually set plan",});@@ -806,7 +806,7 @@ export class BillingService {if (!stripeSubscriptionId)throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "PRECONDITION_FAILED",message: "Organization does not have an active subscription",});@@ -830,7 +830,7 @@ export class BillingService {)) {throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "PRECONDITION_FAILED",message:"Subscription is not active, current status: " +subscription.status,@@ -839,7 +839,7 @@ export class BillingService {if (!StripeCatalogue.isValidCheckoutProduct(newProductId)) {throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "BAD_REQUEST",message: "Invalid stripe product id for new product",});}@@ -1559,7 +1559,7 @@ export class BillingService {parsedOrg.cloudConfig?.stripe?.activeSubscriptionId;if (!stripeCustomerId) {throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "PRECONDITION_FAILED",message: "No stripe customer or subscription found",});}@@ -1919,7 +1919,7 @@ export class BillingService {parsedOrg.cloudConfig?.stripe?.activeSubscriptionId;if (!subscriptionId)throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",+ code: "PRECONDITION_FAILED",message: "Organization does not have an active subscription",});diff --git a/web/src/features/external-media-storage/server/router.ts b/web/src/features/external-media-storage/server/router.tsindex a2c7f83703..67039d75ae 100644--- a/web/src/features/external-media-storage/server/router.ts+++ b/web/src/features/external-media-storage/server/router.ts@@ -1,5 +1,8 @@import { ForbiddenError, InvalidRequestError } from "@langfuse/shared";-import { logger } from "@langfuse/shared/src/server";+import {+ logger,+ OutboundUrlValidationError,+} from "@langfuse/shared/src/server";import { TRPCError } from "@trpc/server";import { z } from "zod";@@ -13,7 +16,10 @@ import {} from "@/src/server/api/trpc";function asBadRequest(error: unknown): never {- if (error instanceof InvalidRequestError) {+ if (+ error instanceof InvalidRequestError ||+ error instanceof OutboundUrlValidationError+ ) {throw new TRPCError({ code: "BAD_REQUEST", message: error.message });}throw error;diff --git a/web/src/features/prompts/server/routers/promptRouter.ts b/web/src/features/prompts/server/routers/promptRouter.tsindex 41400a9187..0615b8f317 100644--- a/web/src/features/prompts/server/routers/promptRouter.ts+++ b/web/src/features/prompts/server/routers/promptRouter.ts@@ -119,7 +119,7 @@ export const promptRouter = createTRPCRouter({const orderByCondition = orderByToPrismaSql(normalizeOrderByForTable({- orderBy: input.orderBy,+ orderBy: input.orderBy ?? { column: "createdAt", order: "DESC" },expectedTimeColumn: "createdAt",}),promptsTableCols,