diff --git a/packages/stack-server/src/app/(main)/(protected)/projects/[projectId]/use-admin-app.tsx b/packages/stack-server/src/app/(main)/(protected)/projects/[projectId]/use-admin-app.tsx index d33e76499..4b723f690 100644 --- a/packages/stack-server/src/app/(main)/(protected)/projects/[projectId]/use-admin-app.tsx +++ b/packages/stack-server/src/app/(main)/(protected)/projects/[projectId]/use-admin-app.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useUser } from "@stackframe/stack"; -import { throwErr } from "@stackframe/stack-shared/dist/utils/errors"; +import { StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/utils/errors"; import { cacheFunction } from "@stackframe/stack-shared/dist/utils/caches"; import { CurrentUser, StackAdminApp } from "@stackframe/stack"; @@ -39,7 +39,7 @@ export function AdminAppProvider(props: { projectId: string, children: React.Rea export function useAdminApp() { const stackAdminApp = React.useContext(StackAdminAppContext); if (!stackAdminApp) { - throw new Error("useAdminApp must be used within a AdminInterfaceProvider"); + throw new StackAssertionError("useAdminApp must be used within an AdminInterfaceProvider"); } return stackAdminApp; diff --git a/packages/stack-server/src/app/api/v1/auth/callback/[provider]/route.tsx b/packages/stack-server/src/app/api/v1/auth/callback/[provider]/route.tsx index 6155a9fc3..1c7c30333 100644 --- a/packages/stack-server/src/app/api/v1/auth/callback/[provider]/route.tsx +++ b/packages/stack-server/src/app/api/v1/auth/callback/[provider]/route.tsx @@ -45,7 +45,7 @@ export const GET = deprecatedSmartRouteHandler(async (req: NextRequest, options: const cookie = cookies().get("stack-oauth"); if (!cookie) { - throw new Error("stack-oauth cookie not found"); + throw new StatusError(StatusError.BadRequest, "stack-oauth cookie not found"); } let decoded: Awaited>; diff --git a/packages/stack-server/src/app/api/v1/auth/password-reset/route.tsx b/packages/stack-server/src/app/api/v1/auth/password-reset/route.tsx index 0d106e1fb..14bcae2df 100644 --- a/packages/stack-server/src/app/api/v1/auth/password-reset/route.tsx +++ b/packages/stack-server/src/app/api/v1/auth/password-reset/route.tsx @@ -5,6 +5,7 @@ import { deprecatedSmartRouteHandler } from "@/route-handlers/smart-route-handle import { deprecatedParseRequest } from "@/route-handlers/smart-request"; import { hashPassword } from "@stackframe/stack-shared/dist/utils/password"; import { KnownErrors } from "@stackframe/stack-shared"; +import { StatusError } from "@stackframe/stack-shared/dist/utils/errors"; const postSchema = yup.object({ body: yup.object({ @@ -40,7 +41,7 @@ export const POST = deprecatedSmartRouteHandler(async (req: NextRequest) => { } if (!password) { - throw new Error("Password is required when onlyVerify is false"); + throw new StatusError(StatusError.BadRequest, "Password is required when onlyVerify is false"); } await prismaClient.projectUser.update({ diff --git a/packages/stack-server/src/app/api/v1/auth/signup/route.tsx b/packages/stack-server/src/app/api/v1/auth/signup/route.tsx index e39651201..b91a7423d 100644 --- a/packages/stack-server/src/app/api/v1/auth/signup/route.tsx +++ b/packages/stack-server/src/app/api/v1/auth/signup/route.tsx @@ -11,7 +11,7 @@ import { getProject } from "@/lib/projects"; import { validateUrl } from "@/utils/url"; import { getPasswordError } from "@stackframe/stack-shared/dist/helpers/password"; import { getApiKeySet, publishableClientKeyHeaderSchema } from "@/lib/api-keys"; -import { StatusError, captureError } from "@stackframe/stack-shared/dist/utils/errors"; +import { StackAssertionError, StatusError, captureError } from "@stackframe/stack-shared/dist/utils/errors"; import { KnownErrors } from "@stackframe/stack-shared"; import { createTeamOnSignUp } from "@/lib/users"; @@ -51,7 +51,7 @@ export const POST = deprecatedSmartRouteHandler(async (req: NextRequest) => { const project = await getProject(projectId); if (!project) { - throw new Error("Project not found"); // This should never happen, make typescript happy + throw new StackAssertionError("Project not found. This should never happen"); // This should never happen, make typescript happy } if (!project.evaluatedConfig.credentialEnabled) { diff --git a/packages/stack-server/src/app/api/v1/projects/[projectId]/route.tsx b/packages/stack-server/src/app/api/v1/projects/[projectId]/route.tsx index 2f9e9cc45..6ca2e260c 100644 --- a/packages/stack-server/src/app/api/v1/projects/[projectId]/route.tsx +++ b/packages/stack-server/src/app/api/v1/projects/[projectId]/route.tsx @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from "next/server"; import * as yup from "yup"; -import { StatusError } from "@stackframe/stack-shared/dist/utils/errors"; +import { StackAssertionError, StatusError } from "@stackframe/stack-shared/dist/utils/errors"; import { deprecatedSmartRouteHandler } from "@/route-handlers/smart-route-handler"; import { deprecatedParseRequest } from "@/route-handlers/smart-request"; import { checkApiKeySet, publishableClientKeyHeaderSchema, superSecretAdminKeyHeaderSchema } from "@/lib/api-keys"; @@ -50,7 +50,7 @@ const handler = deprecatedSmartRouteHandler(async (req: NextRequest, options: { const project = await getProject(projectId); if (!project) { - throw new Error("Project not found but the API key was valid? Something weird happened"); + throw new StackAssertionError("Project not found but the API key was valid? Something weird happened"); } const clientProject: ClientProjectJson = { id: project.id, diff --git a/packages/stack-server/src/components/ui/form.tsx b/packages/stack-server/src/components/ui/form.tsx index 6ab1e72bd..7bcfc4efa 100644 --- a/packages/stack-server/src/components/ui/form.tsx +++ b/packages/stack-server/src/components/ui/form.tsx @@ -12,6 +12,7 @@ import { import { cn } from "@/lib/utils"; import { Label, SpanLabel } from "@/components/ui/label"; +import { StackAssertionError } from "@stackframe/stack-shared/dist/utils/errors"; const Form = FormProvider; @@ -47,7 +48,7 @@ const useFormField = () => { const fieldState = getFieldState(fieldContext.name, formState); if (!fieldContext) { - throw new Error("useFormField should be used within "); + throw new StackAssertionError("useFormField should be used within "); } const { id } = itemContext;