From cc0eeddc9b7e6c9c514d5350dd6559c28573db5b Mon Sep 17 00:00:00 2001 From: James P Date: Thu, 19 Sep 2024 12:48:31 -0400 Subject: [PATCH] fix: Improve errors and remove parser to get accurate toasts (#2115) * remove trpcError parser Update errors to handle DB fails which will give a user a good error if a DB operation fails * Fix root key to actually error * [autofix.ci] apply automated fixes * Update apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update update-key-name.tsx * [autofix.ci] apply automated fixes * Update update-root-key-name.tsx * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../keys/[keyAuthId]/[keyId]/role-toggle.tsx | 11 +-- .../[keyId]/settings/delete-key.tsx | 4 +- .../[keyId]/settings/update-key-enabled.tsx | 4 +- .../settings/update-key-expiration.tsx | 5 +- .../[keyId]/settings/update-key-metadata.tsx | 4 +- .../[keyId]/settings/update-key-name.tsx | 5 +- .../[keyId]/settings/update-key-owner-id.tsx | 5 +- .../[keyId]/settings/update-key-ratelimit.tsx | 5 +- .../[keyId]/settings/update-key-remaining.tsx | 9 +- .../[apiId]/keys/[keyAuthId]/new/client.tsx | 4 +- .../apis/[apiId]/settings/delete-api.tsx | 5 +- .../[apiId]/settings/delete-protection.tsx | 10 +- .../apis/[apiId]/settings/update-api-name.tsx | 4 +- .../[apiId]/settings/update-ip-whitelist.tsx | 5 +- .../app/(app)/apis/create-api-button.tsx | 6 +- .../permissions/[permissionId]/client.tsx | 6 -- .../[permissionId]/delete-permission.tsx | 6 -- .../permissions/create-new-permission.tsx | 6 -- .../roles/[roleId]/delete-role.tsx | 6 -- .../roles/[roleId]/permission-toggle.tsx | 11 +-- .../roles/[roleId]/update-role.tsx | 6 -- .../authorization/roles/create-new-role.tsx | 13 ++- .../dashboard/app/(app)/gateways/new/form.tsx | 16 +-- .../verifications/create-new-button.tsx | 6 -- .../overrides/[overrideId]/settings.tsx | 11 --- .../overrides/create-new-override.tsx | 6 -- .../settings/delete-namespace.tsx | 7 -- .../settings/update-namespace-name.tsx | 6 -- .../ratelimits/create-namespace-button.tsx | 6 -- apps/dashboard/app/(app)/secrets/new/form.tsx | 6 -- apps/dashboard/app/(app)/secrets/secrets.tsx | 12 +-- .../[gatewayId]/settings/delete-gateway.tsx | 6 +- .../app/(app)/semantic-cache/form.tsx | 6 -- .../(app)/settings/billing/plans/button.tsx | 6 +- .../general/update-workspace-name.tsx | 6 -- .../root-keys/[keyId]/permissions/legacy.tsx | 6 +- .../[keyId]/permissions/permission_toggle.tsx | 16 +-- .../[keyId]/update-root-key-name.tsx | 6 +- .../(app)/settings/root-keys/new/client.tsx | 4 +- .../app/(app)/settings/vercel/client.tsx | 23 +++-- .../[webhookId]/toggle-webhook-button.tsx | 6 -- .../webhooks/create-webhook-button.tsx | 6 -- .../integrations/vercel/callback/client.tsx | 11 ++- apps/dashboard/app/new/create-api.tsx | 6 -- .../app/new/create-semantic-cache.tsx | 6 -- apps/dashboard/app/new/create-workspace.tsx | 6 -- apps/dashboard/app/new/keys.tsx | 11 --- .../components/dashboard/command-menu.tsx | 6 +- apps/dashboard/lib/trpc/routers/api/create.ts | 15 ++- apps/dashboard/lib/trpc/routers/api/delete.ts | 22 +++-- .../routers/api/updateDeleteProtection.ts | 22 +++-- .../lib/trpc/routers/api/updateIpWhitelist.ts | 22 +++-- .../lib/trpc/routers/api/updateName.ts | 22 +++-- .../lib/trpc/routers/gateway/create.ts | 16 ++- apps/dashboard/lib/trpc/routers/key/create.ts | 36 +++++-- .../lib/trpc/routers/key/createRootKey.ts | 36 +++++-- apps/dashboard/lib/trpc/routers/key/delete.ts | 30 +++--- .../lib/trpc/routers/key/deleteRootKey.ts | 18 +++- .../lib/trpc/routers/key/updateEnabled.ts | 22 +++-- .../lib/trpc/routers/key/updateExpiration.ts | 22 +++-- .../lib/trpc/routers/key/updateMetadata.ts | 22 +++-- .../lib/trpc/routers/key/updateName.ts | 22 +++-- .../lib/trpc/routers/key/updateOwnerId.ts | 22 +++-- .../lib/trpc/routers/key/updateRatelimit.ts | 22 +++-- .../lib/trpc/routers/key/updateRemaining.ts | 22 +++-- .../lib/trpc/routers/key/updateRootKeyName.ts | 18 +++- .../lib/trpc/routers/llmGateway/create.ts | 21 +++- .../lib/trpc/routers/llmGateway/delete.ts | 26 +++-- .../routers/monitor/verification/create.ts | 28 ++++-- .../trpc/routers/ratelimit/createNamespace.ts | 21 +++- .../trpc/routers/ratelimit/createOverride.ts | 30 +++--- .../trpc/routers/ratelimit/deleteNamespace.ts | 28 ++++-- .../trpc/routers/ratelimit/deleteOverride.ts | 36 ++++--- .../routers/ratelimit/updateNamespaceName.ts | 26 +++-- .../trpc/routers/ratelimit/updateOverride.ts | 36 ++++--- .../routers/rbac/addPermissionToRootKey.ts | 16 ++- .../routers/rbac/connectPermissionToRole.ts | 30 +++--- .../lib/trpc/routers/rbac/connectRoleToKey.ts | 30 +++--- .../lib/trpc/routers/rbac/createPermission.ts | 16 ++- .../lib/trpc/routers/rbac/createRole.ts | 15 ++- .../lib/trpc/routers/rbac/deletePermission.ts | 24 +++-- .../lib/trpc/routers/rbac/deleteRole.ts | 23 +++-- .../rbac/disconnectPermissionFromRole.ts | 16 ++- .../routers/rbac/disconnectRoleFromKey.ts | 16 ++- .../rbac/removePermissionFromRootKey.ts | 50 ++++++---- .../lib/trpc/routers/rbac/updatePermission.ts | 24 +++-- .../lib/trpc/routers/rbac/updateRole.ts | 24 +++-- .../lib/trpc/routers/rbac/upsertPermission.ts | 15 ++- .../lib/trpc/routers/secrets/create.ts | 15 ++- .../lib/trpc/routers/secrets/decrypt.ts | 24 +++-- .../lib/trpc/routers/secrets/update.ts | 28 ++++-- .../lib/trpc/routers/webhook/create.ts | 99 +++++++++++++------ .../lib/trpc/routers/webhook/delete.ts | 24 +++-- .../lib/trpc/routers/webhook/toggle.ts | 24 +++-- .../lib/trpc/routers/workspace/changeName.ts | 16 ++- .../lib/trpc/routers/workspace/changePlan.ts | 24 ++++- .../lib/trpc/routers/workspace/optIntoBeta.ts | 16 ++- apps/dashboard/lib/utils.ts | 5 - 98 files changed, 938 insertions(+), 652 deletions(-) diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/role-toggle.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/role-toggle.tsx index 7cd3f7568b..f6c8a855d0 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/role-toggle.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/role-toggle.tsx @@ -3,7 +3,6 @@ import { Checkbox } from "@/components/ui/checkbox"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { Loader2 } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -33,10 +32,9 @@ export const RoleToggle: React.FC = ({ roleId, keyId, checked }) => { }, }); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, onSettled: () => { router.refresh(); @@ -58,10 +56,9 @@ export const RoleToggle: React.FC = ({ roleId, keyId, checked }) => { }, }); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, onSettled: () => { router.refresh(); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/delete-key.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/delete-key.tsx index 18485bcbe9..531ce15e4f 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/delete-key.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/delete-key.tsx @@ -17,7 +17,6 @@ import { DialogTitle, } from "@/components/ui/dialog"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { useRouter } from "next/navigation"; type Props = { @@ -39,8 +38,7 @@ export const DeleteKey: React.FC = ({ apiKey, keyAuthId }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-enabled.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-enabled.tsx index be0fbb76f9..24c1dcfe61 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-enabled.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-enabled.tsx @@ -13,7 +13,6 @@ import { Form, FormControl, FormField, FormItem, FormLabel } from "@/components/ import { Switch } from "@/components/ui/switch"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; @@ -52,8 +51,7 @@ export const UpdateKeyEnabled: React.FC = ({ apiKey }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-expiration.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-expiration.tsx index 794e17ac6c..6e4a51f63e 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-expiration.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-expiration.tsx @@ -22,7 +22,7 @@ import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { format } from "date-fns"; @@ -74,8 +74,7 @@ export const UpdateKeyExpiration: React.FC = ({ apiKey }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-metadata.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-metadata.tsx index 97ec9821f9..37d06d77f0 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-metadata.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-metadata.tsx @@ -14,7 +14,6 @@ import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; @@ -54,8 +53,7 @@ export const UpdateKeyMetadata: React.FC = ({ apiKey }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx index fce5e20b67..7981ec5b86 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx @@ -14,7 +14,7 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; @@ -56,8 +56,7 @@ export const UpdateKeyName: React.FC = ({ apiKey }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx index b8b6e973aa..bc471b242f 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx @@ -14,7 +14,7 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; @@ -57,8 +57,7 @@ export const UpdateKeyOwnerId: React.FC = ({ apiKey }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-ratelimit.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-ratelimit.tsx index cad71ef736..720816f161 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-ratelimit.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-ratelimit.tsx @@ -23,7 +23,7 @@ import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import type { Key } from "@unkey/db"; import { useRouter } from "next/navigation"; @@ -90,8 +90,7 @@ export const UpdateKeyRatelimit: React.FC = ({ apiKey }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx index 8054500e03..5030b63087 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-remaining.tsx @@ -30,7 +30,7 @@ import { import { Switch } from "@/components/ui/switch"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; @@ -95,14 +95,15 @@ export const UpdateKeyRemaining: React.FC = ({ apiKey }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); async function onSubmit(values: z.infer) { if (values.refill?.interval !== "none" && !values.refill?.amount) { - form.setError("refill.amount", { message: "Please enter the number of uses per interval" }); + form.setError("refill.amount", { + message: "Please enter the number of uses per interval", + }); return; } if (values.refill.interval !== "none" && values.remaining === undefined) { diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx index 99a264dcd9..e8102431b0 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx @@ -30,7 +30,6 @@ import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { AlertCircle } from "lucide-react"; import Link from "next/link"; @@ -176,8 +175,7 @@ export const CreateKey: React.FC = ({ apiId, keyAuthId }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/settings/delete-api.tsx b/apps/dashboard/app/(app)/apis/[apiId]/settings/delete-api.tsx index 8ae150c454..b4629fa8ec 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/settings/delete-api.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/settings/delete-api.tsx @@ -31,7 +31,7 @@ import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { z } from "zod"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; import { revalidate } from "./actions"; type Props = { @@ -74,8 +74,7 @@ export const DeleteApi: React.FC = ({ api, keys }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/settings/delete-protection.tsx b/apps/dashboard/app/(app)/apis/[apiId]/settings/delete-protection.tsx index e186c0194f..a7d3b8d7e6 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/settings/delete-protection.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/settings/delete-protection.tsx @@ -29,8 +29,6 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { z } from "zod"; - -import { parseTrpcError } from "@/lib/utils"; import { revalidate } from "./actions"; type Props = { @@ -68,15 +66,17 @@ export const DeleteProtection: React.FC = ({ api }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); const isValid = form.watch("name") === api.name; async function onSubmit(_: z.infer) { - updateDeleteProtection.mutate({ apiId: api.id, enabled: !api.deleteProtection }); + updateDeleteProtection.mutate({ + apiId: api.id, + enabled: !api.deleteProtection, + }); } if (api.deleteProtection) { diff --git a/apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx b/apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx index 52a219811b..bf3502aa0a 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx @@ -13,7 +13,6 @@ import { FormField } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; @@ -50,8 +49,7 @@ export const UpdateApiName: React.FC = ({ api }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/apis/[apiId]/settings/update-ip-whitelist.tsx b/apps/dashboard/app/(app)/apis/[apiId]/settings/update-ip-whitelist.tsx index e188e4e5b6..4f1ca6437e 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/settings/update-ip-whitelist.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/settings/update-ip-whitelist.tsx @@ -14,7 +14,7 @@ import { FormField } from "@/components/ui/form"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import type { Workspace } from "@unkey/db"; import Link from "next/link"; @@ -60,8 +60,7 @@ export const UpdateIpWhitelist: React.FC = ({ api, workspace }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/apis/create-api-button.tsx b/apps/dashboard/app/(app)/apis/create-api-button.tsx index 3cd3b862f2..a53ab6de9c 100644 --- a/apps/dashboard/app/(app)/apis/create-api-button.tsx +++ b/apps/dashboard/app/(app)/apis/create-api-button.tsx @@ -14,7 +14,6 @@ import { import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { Plus } from "lucide-react"; import { useRouter } from "next/navigation"; @@ -38,9 +37,8 @@ export const CreateApiButton = ({ ...rest }: React.ButtonHTMLAttributes) { diff --git a/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/client.tsx b/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/client.tsx index 949d27b517..725971d8ef 100644 --- a/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/client.tsx +++ b/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/client.tsx @@ -17,7 +17,6 @@ import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import type { Permission } from "@unkey/db"; import { useRouter } from "next/navigation"; @@ -50,11 +49,6 @@ export const Client: React.FC = ({ permission }) => { toast.success("Permission updated"); router.refresh(); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx b/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx index f26f6db3e2..691c130acd 100644 --- a/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx +++ b/apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx @@ -23,7 +23,6 @@ import { import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { DialogTrigger } from "@radix-ui/react-dialog"; import { useRouter } from "next/navigation"; @@ -60,11 +59,6 @@ export const DeletePermission: React.FC = ({ trigger, permission }) => { revalidate("/authorization/permissions"); router.push("/authorization/permissions"); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit() { diff --git a/apps/dashboard/app/(app)/authorization/permissions/create-new-permission.tsx b/apps/dashboard/app/(app)/authorization/permissions/create-new-permission.tsx index e43a4317d0..95865b7f51 100644 --- a/apps/dashboard/app/(app)/authorization/permissions/create-new-permission.tsx +++ b/apps/dashboard/app/(app)/authorization/permissions/create-new-permission.tsx @@ -25,7 +25,6 @@ import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { DialogTrigger } from "@radix-ui/react-dialog"; import { useRouter } from "next/navigation"; @@ -68,11 +67,6 @@ export const CreateNewPermission: React.FC = ({ trigger }) => { }); setOpen(false); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx b/apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx index 96fe0ae778..a82b265810 100644 --- a/apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx +++ b/apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx @@ -22,7 +22,6 @@ import { import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { DialogTrigger } from "@radix-ui/react-dialog"; import { useRouter } from "next/navigation"; @@ -61,11 +60,6 @@ export const DeleteRole: React.FC = ({ trigger, role }) => { toast.success("Role deleted successfully"); router.push("/authorization/roles"); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit() { diff --git a/apps/dashboard/app/(app)/authorization/roles/[roleId]/permission-toggle.tsx b/apps/dashboard/app/(app)/authorization/roles/[roleId]/permission-toggle.tsx index 6d8d4c9ae2..0e1e509acf 100644 --- a/apps/dashboard/app/(app)/authorization/roles/[roleId]/permission-toggle.tsx +++ b/apps/dashboard/app/(app)/authorization/roles/[roleId]/permission-toggle.tsx @@ -3,7 +3,6 @@ import { Checkbox } from "@/components/ui/checkbox"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { Loader2 } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -33,10 +32,9 @@ export const PermissionToggle: React.FC = ({ roleId, permissionId, checke }, }); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, onSettled: () => { router.refresh(); @@ -58,10 +56,9 @@ export const PermissionToggle: React.FC = ({ roleId, permissionId, checke }, }); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, onSettled: () => { router.refresh(); diff --git a/apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx b/apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx index e14f51a87b..2ea3a2a6bf 100644 --- a/apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx +++ b/apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx @@ -23,7 +23,6 @@ import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { DialogTrigger } from "@radix-ui/react-dialog"; import type { Role } from "@unkey/db"; @@ -63,11 +62,6 @@ export const UpdateRole: React.FC = ({ trigger, role }) => { router.refresh(); setOpen(false); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/authorization/roles/create-new-role.tsx b/apps/dashboard/app/(app)/authorization/roles/create-new-role.tsx index 279c7b9fb3..c9840ee2db 100644 --- a/apps/dashboard/app/(app)/authorization/roles/create-new-role.tsx +++ b/apps/dashboard/app/(app)/authorization/roles/create-new-role.tsx @@ -26,7 +26,6 @@ import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { DialogTrigger } from "@radix-ui/react-dialog"; import type { Permission } from "@unkey/db"; @@ -81,11 +80,8 @@ export const CreateNewRole: React.FC = ({ trigger, permissions }) => { router.push(`/authorization/roles/${roleId}`); }, onError(err) { - console.error(err.message); - let temp = JSON.parse(err.message); - temp = temp.at(0).message; - const message = parseTrpcError(err); - toast.error(message); + console.error(err); + toast.error(err.message); }, }); @@ -161,7 +157,10 @@ export const CreateNewRole: React.FC = ({ trigger, permissions }) => { ({ label: p.name, value: p.id }))} + options={permissions.map((p) => ({ + label: p.name, + value: p.id, + }))} selected={field.value ?? []} setSelected={(cb) => { if (typeof cb === "function") { diff --git a/apps/dashboard/app/(app)/gateways/new/form.tsx b/apps/dashboard/app/(app)/gateways/new/form.tsx index fd2a525aa7..50cd4f3f4e 100644 --- a/apps/dashboard/app/(app)/gateways/new/form.tsx +++ b/apps/dashboard/app/(app)/gateways/new/form.tsx @@ -24,7 +24,6 @@ import { } from "@/components/ui/table"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import * as AccordionPrimitive from "@radix-ui/react-accordion"; import { ChevronDown, Eye, EyeOff, X } from "lucide-react"; @@ -52,7 +51,10 @@ export const CreateGatewayForm: React.FC = () => { shouldFocusError: true, }); - const fields = useFieldArray({ control: form.control, name: "headerRewrites" }); + const fields = useFieldArray({ + control: form.control, + name: "headerRewrites", + }); const create = trpc.gateway.create.useMutation({ onSuccess(_, variables) { toast.success("Gateway Created", { @@ -66,11 +68,6 @@ export const CreateGatewayForm: React.FC = () => { }, }); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { @@ -245,7 +242,10 @@ export const CreateGatewayForm: React.FC = () => { variant="secondary" size="icon" onClick={() => { - fields.update(index, { ...f, show: !f.show }); + fields.update(index, { + ...f, + show: !f.show, + }); }} > {f.show ? ( diff --git a/apps/dashboard/app/(app)/monitors/verifications/create-new-button.tsx b/apps/dashboard/app/(app)/monitors/verifications/create-new-button.tsx index 0fc22aef04..9ed8aeb53b 100644 --- a/apps/dashboard/app/(app)/monitors/verifications/create-new-button.tsx +++ b/apps/dashboard/app/(app)/monitors/verifications/create-new-button.tsx @@ -21,7 +21,6 @@ import { } from "@/components/ui/select"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import type { Workspace } from "@unkey/db"; import { Plus } from "lucide-react"; @@ -60,11 +59,6 @@ export const CreateNewMonitorButton: React.FC = ({ workspace, keySpaces } router.refresh(); router.push("/webhooks"); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { create.mutate({ diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/[overrideId]/settings.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/[overrideId]/settings.tsx index 95e6cf1a84..fad55095a1 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/[overrideId]/settings.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/[overrideId]/settings.tsx @@ -30,7 +30,6 @@ import { } from "@/components/ui/select"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import type React from "react"; @@ -80,11 +79,6 @@ export const UpdateCard: React.FC = ({ overrideId, defaultValues }) => { }); router.refresh(); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); const deleteOverride = trpc.ratelimit.override.delete.useMutation({ @@ -94,11 +88,6 @@ export const UpdateCard: React.FC = ({ overrideId, defaultValues }) => { }); router.push("/ratelimits/"); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx index 00d16c58a1..5d21514709 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx @@ -21,7 +21,6 @@ import { } from "@/components/ui/select"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter, useSearchParams } from "next/navigation"; import type React from "react"; @@ -64,11 +63,6 @@ export const CreateNewOverride: React.FC = ({ namespaceId }) => { }); router.refresh(); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { create.mutate({ diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/delete-namespace.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/delete-namespace.tsx index 00f5bba45d..b38cc79501 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/delete-namespace.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/delete-namespace.tsx @@ -30,8 +30,6 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { z } from "zod"; - -import { parseTrpcError } from "@/lib/utils"; import { revalidate } from "./actions"; type Props = { @@ -67,11 +65,6 @@ export const DeleteNamespace: React.FC = ({ namespace }) => { router.push("/ratelimits"); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); const isValid = form.watch("intent") === intent && form.watch("name") === namespace.name; diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx index ff2aa9c23e..abbdddc3b1 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx @@ -13,7 +13,6 @@ import { FormField } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; @@ -48,11 +47,6 @@ export const UpdateNamespaceName: React.FC = ({ namespace }) => { toast.success("Your namespace name has been renamed!"); router.refresh(); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { if (values.name === namespace.name || !values.name) { diff --git a/apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx b/apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx index 5b18d80d83..32b8367c51 100644 --- a/apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx +++ b/apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx @@ -14,7 +14,6 @@ import { import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { Plus } from "lucide-react"; import { useRouter } from "next/navigation"; @@ -39,11 +38,6 @@ export const CreateNamespaceButton = ({ router.refresh(); router.push(`/ratelimits/${res.id}`); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { create.mutate(values); diff --git a/apps/dashboard/app/(app)/secrets/new/form.tsx b/apps/dashboard/app/(app)/secrets/new/form.tsx index 8be5c86fe2..17fd321ea0 100644 --- a/apps/dashboard/app/(app)/secrets/new/form.tsx +++ b/apps/dashboard/app/(app)/secrets/new/form.tsx @@ -13,7 +13,6 @@ import { Input } from "@/components/ui/input"; import { Separator } from "@/components/ui/separator"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; @@ -38,11 +37,6 @@ export const CreateSecretForm: React.FC = () => { toast.success("Secret created"); router.refresh(); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/secrets/secrets.tsx b/apps/dashboard/app/(app)/secrets/secrets.tsx index 8aeac725f1..a07af8b876 100644 --- a/apps/dashboard/app/(app)/secrets/secrets.tsx +++ b/apps/dashboard/app/(app)/secrets/secrets.tsx @@ -30,7 +30,7 @@ import { DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Separator } from "@/components/ui/separator"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; type Props = { secrets: Secret[]; @@ -93,11 +93,6 @@ const Row: React.FC<{ secret: Secret }> = ({ secret }) => { toast.success("Secret updated"); router.refresh(); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { @@ -229,10 +224,9 @@ const Row: React.FC<{ secret: Secret }> = ({ secret }) => { const Value: React.FC<{ secretId: string }> = ({ secretId }) => { const decrypt = trpc.secrets.decrypt.useMutation({ - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/semantic-cache/[gatewayId]/settings/delete-gateway.tsx b/apps/dashboard/app/(app)/semantic-cache/[gatewayId]/settings/delete-gateway.tsx index b71021751a..9ec6c59c0b 100644 --- a/apps/dashboard/app/(app)/semantic-cache/[gatewayId]/settings/delete-gateway.tsx +++ b/apps/dashboard/app/(app)/semantic-cache/[gatewayId]/settings/delete-gateway.tsx @@ -26,7 +26,6 @@ import { FormMessage, } from "@/components/ui/form"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { PostHogEvent } from "@/providers/PostHogProvider"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; @@ -71,10 +70,9 @@ export const DeleteGateway: React.FC = ({ gateway }) => { router.push("/semantic-cache"); }, - onError(err: { message: string }) { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/semantic-cache/form.tsx b/apps/dashboard/app/(app)/semantic-cache/form.tsx index e65c33e680..a2c2d46b30 100644 --- a/apps/dashboard/app/(app)/semantic-cache/form.tsx +++ b/apps/dashboard/app/(app)/semantic-cache/form.tsx @@ -12,7 +12,6 @@ import { } from "@/components/ui/form"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { PostHogEvent } from "@/providers/PostHogProvider"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; @@ -47,11 +46,6 @@ export const CreateLLMGatewayForm: React.FC = () => { }); router.push(`/semantic-cache/${res.id}/logs`); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/settings/billing/plans/button.tsx b/apps/dashboard/app/(app)/settings/billing/plans/button.tsx index 530033ad72..fa15a8a150 100644 --- a/apps/dashboard/app/(app)/settings/billing/plans/button.tsx +++ b/apps/dashboard/app/(app)/settings/billing/plans/button.tsx @@ -12,7 +12,6 @@ import { } from "@/components/ui/dialog"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { PostHogEvent } from "@/providers/PostHogProvider"; import type { Workspace } from "@unkey/db"; import { useRouter } from "next/navigation"; @@ -40,10 +39,9 @@ export const ChangePlanButton: React.FC = ({ workspace, newPlan, label }) setOpen(false); router.refresh(); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx b/apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx index d7ed9a39ce..a2a2b82f54 100644 --- a/apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx +++ b/apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx @@ -6,7 +6,6 @@ import { Form, FormControl, FormField, FormItem, FormMessage } from "@/component import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { useUser } from "@clerk/nextjs"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; @@ -46,11 +45,6 @@ export const UpdateWorkspaceName: React.FC = ({ workspace }) => { user?.reload(); router.refresh(); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onSubmit(values: z.infer) { diff --git a/apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/legacy.tsx b/apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/legacy.tsx index 25fe2f617c..3198381f7d 100644 --- a/apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/legacy.tsx +++ b/apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/legacy.tsx @@ -12,7 +12,6 @@ import { } from "@/components/ui/card"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import type { Permission } from "@unkey/db"; import { Loader2 } from "lucide-react"; import { useRouter } from "next/navigation"; @@ -31,10 +30,9 @@ export const Legacy: React.FC = ({ keyId, permissions }) => { }); router.refresh(); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, onSettled: () => {}, }); diff --git a/apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/permission_toggle.tsx b/apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/permission_toggle.tsx index f463f13052..c23c8322c0 100644 --- a/apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/permission_toggle.tsx +++ b/apps/dashboard/app/(app)/settings/root-keys/[keyId]/permissions/permission_toggle.tsx @@ -6,7 +6,6 @@ import { Label } from "@/components/ui/label"; import { toast } from "@/components/ui/toaster"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { Loader2 } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -41,10 +40,9 @@ export const PermissionToggle: React.FC = ({ description: "Changes may take up to 60 seconds to take effect.", }); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, onSettled: () => { router.refresh(); @@ -65,10 +63,9 @@ export const PermissionToggle: React.FC = ({ }, }); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, onSettled: () => { router.refresh(); @@ -98,7 +95,10 @@ export const PermissionToggle: React.FC = ({ } } else { if (!preventEnabling) { - addPermission.mutate({ rootKeyId, permission: permissionName }); + addPermission.mutate({ + rootKeyId, + permission: permissionName, + }); } } }} diff --git a/apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx b/apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx index aeb6d5c35b..976d408dc8 100644 --- a/apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx +++ b/apps/dashboard/app/(app)/settings/root-keys/[keyId]/update-root-key-name.tsx @@ -14,12 +14,11 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { cn, parseTrpcError } from "@/lib/utils"; +import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { z } from "zod"; - const formSchema = z.object({ keyId: z.string(), name: z @@ -55,8 +54,7 @@ export const UpdateRootKeyName: React.FC = ({ apiKey }) => { }, onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/settings/root-keys/new/client.tsx b/apps/dashboard/app/(app)/settings/root-keys/new/client.tsx index f5a879de94..80ebc511bf 100644 --- a/apps/dashboard/app/(app)/settings/root-keys/new/client.tsx +++ b/apps/dashboard/app/(app)/settings/root-keys/new/client.tsx @@ -21,7 +21,6 @@ import { Label } from "@/components/ui/label"; import { toast } from "@/components/ui/toaster"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import type { UnkeyPermission } from "@unkey/rbac"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -41,8 +40,7 @@ export const Client: React.FC = ({ apis }) => { const key = trpc.rootKey.create.useMutation({ onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/app/(app)/settings/vercel/client.tsx b/apps/dashboard/app/(app)/settings/vercel/client.tsx index c2850c9ca7..29dc4eaa66 100644 --- a/apps/dashboard/app/(app)/settings/vercel/client.tsx +++ b/apps/dashboard/app/(app)/settings/vercel/client.tsx @@ -24,7 +24,6 @@ import { import { toast } from "@/components/ui/toaster"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { cn } from "@/lib/utils"; import type { Api, Key, VercelBinding } from "@unkey/db"; import { ExternalLink, Link2, MoreHorizontal, Plus, RefreshCw, Trash, Unlink2 } from "lucide-react"; @@ -214,10 +213,9 @@ const ConnectedResource: React.FC<{ router.refresh(); toast.success("Updated the environment variable in Vercel"); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); @@ -228,10 +226,9 @@ const ConnectedResource: React.FC<{ "Successfully rolled your root key and updated the environment variable in Vercel", ); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); const unbind = trpc.vercel.unbind.useMutation({ @@ -239,10 +236,9 @@ const ConnectedResource: React.FC<{ router.refresh(); toast.success(`Successfully unbound ${props.type} from Vercel`); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); @@ -300,8 +296,11 @@ const ConnectedResource: React.FC<{ <> - Edited {ms(Date.now() - props.binding?.updatedAt.getTime(), { long: true })} ago - by {props.binding?.updatedBy.name} + Edited{" "} + {ms(Date.now() - props.binding?.updatedAt.getTime(), { + long: true, + })}{" "} + ago by {props.binding?.updatedBy.name} = ({ webhook }) => { onSuccess() { router.refresh(); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function action(enabled: boolean) { diff --git a/apps/dashboard/app/(app)/settings/webhooks/create-webhook-button.tsx b/apps/dashboard/app/(app)/settings/webhooks/create-webhook-button.tsx index 2780a3d7bb..4e2b68e249 100644 --- a/apps/dashboard/app/(app)/settings/webhooks/create-webhook-button.tsx +++ b/apps/dashboard/app/(app)/settings/webhooks/create-webhook-button.tsx @@ -15,7 +15,6 @@ import { Input } from "@/components/ui/input"; import { Select } from "@/components/ui/select"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { Plus } from "lucide-react"; import { useRouter } from "next/navigation"; @@ -41,11 +40,6 @@ export const CreateWebhookButton = ({ ...rest }: React.ButtonHTMLAttributes) { create.mutate(values); diff --git a/apps/dashboard/app/integrations/vercel/callback/client.tsx b/apps/dashboard/app/integrations/vercel/callback/client.tsx index ac3c72572c..0a2840b622 100644 --- a/apps/dashboard/app/integrations/vercel/callback/client.tsx +++ b/apps/dashboard/app/integrations/vercel/callback/client.tsx @@ -13,7 +13,6 @@ import { } from "@/components/ui/select"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import type { Api, VercelBinding } from "@unkey/db"; import { X } from "lucide-react"; import { useRouter } from "next/navigation"; @@ -59,10 +58,9 @@ export const Client: React.FC = ({ toast("Redirecting back to Vercel"); router.push(returnUrl); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); @@ -138,7 +136,10 @@ export const Client: React.FC = ({ variant="ghost" size="icon" onClick={() => { - setSelectedApis({ ...selectedApis, [environment]: null }); + setSelectedApis({ + ...selectedApis, + [environment]: null, + }); }} > diff --git a/apps/dashboard/app/new/create-api.tsx b/apps/dashboard/app/new/create-api.tsx index aaabd300b6..e1180af3a2 100644 --- a/apps/dashboard/app/new/create-api.tsx +++ b/apps/dashboard/app/new/create-api.tsx @@ -14,7 +14,6 @@ import { import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { PostHogIdentify } from "@/providers/PostHogProvider"; import { useUser } from "@clerk/nextjs"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -49,11 +48,6 @@ export const CreateApi: React.FC = ({ workspace }) => { form.reset(); router.push(`/new?workspaceId=${workspace.id}&apiId=${apiId}`); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); function AsideContent() { return ( diff --git a/apps/dashboard/app/new/create-semantic-cache.tsx b/apps/dashboard/app/new/create-semantic-cache.tsx index 8278e8de99..76243f70a5 100644 --- a/apps/dashboard/app/new/create-semantic-cache.tsx +++ b/apps/dashboard/app/new/create-semantic-cache.tsx @@ -3,7 +3,6 @@ import { Button } from "@/components/ui/button"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { PostHogEvent } from "@/providers/PostHogProvider"; import { useRouter } from "next/navigation"; import { generateSemanticCacheDefaultName } from "../(app)/semantic-cache/new/util/generate-semantic-cache-default-name"; @@ -23,11 +22,6 @@ export const CreateSemanticCacheButton: React.FC = () => { }); router.push(`/semantic-cache/${res.id}/settings`); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); async function onClick() { createGateway.mutate({ diff --git a/apps/dashboard/app/new/create-workspace.tsx b/apps/dashboard/app/new/create-workspace.tsx index 72ecff8d72..0c9f10cd6b 100644 --- a/apps/dashboard/app/new/create-workspace.tsx +++ b/apps/dashboard/app/new/create-workspace.tsx @@ -15,7 +15,6 @@ import { import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { useOrganizationList } from "@clerk/nextjs"; import { zodResolver } from "@hookform/resolvers/zod"; import { Box } from "lucide-react"; @@ -43,11 +42,6 @@ export const CreateWorkspace: React.FC = () => { } router.push(`/new?workspaceId=${workspace.id}`); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); function AsideContent() { diff --git a/apps/dashboard/app/new/keys.tsx b/apps/dashboard/app/new/keys.tsx index b483e58200..29758c324f 100644 --- a/apps/dashboard/app/new/keys.tsx +++ b/apps/dashboard/app/new/keys.tsx @@ -18,7 +18,6 @@ import { Code } from "@/components/ui/code"; import { Separator } from "@/components/ui/separator"; import { toast } from "@/components/ui/toaster"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { AlertCircle, KeyRound, Lock } from "lucide-react"; import Link from "next/link"; import { useState } from "react"; @@ -51,21 +50,11 @@ export const Keys: React.FC = ({ keyAuthId, apiId }) => { onSuccess(res) { setStep({ step: "CREATE_KEY", rootKey: res.key }); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); const key = trpc.key.create.useMutation({ onSuccess(res) { setStep({ step: "VERIFY_KEY", key: res.key }); }, - onError(err) { - console.error(err); - const message = parseTrpcError(err); - toast.error(message); - }, }); const [showKey, setShowKey] = useState(false); diff --git a/apps/dashboard/components/dashboard/command-menu.tsx b/apps/dashboard/components/dashboard/command-menu.tsx index 7beacaace7..c30941e495 100644 --- a/apps/dashboard/components/dashboard/command-menu.tsx +++ b/apps/dashboard/components/dashboard/command-menu.tsx @@ -16,7 +16,6 @@ import { DialogTitle, } from "@/components/ui/dialog"; import { trpc } from "@/lib/trpc/client"; -import { parseTrpcError } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { BookOpen, type LucideIcon, MessagesSquare } from "lucide-react"; import { useRouter } from "next/navigation"; @@ -137,10 +136,9 @@ const Feedback: React.FC = () => { setOpen(false); toast.success("Your issue has been created, we'll get back to you as soon as possible"); }, - onError: (err) => { + onError(err) { console.error(err); - const message = parseTrpcError(err); - toast.error(message); + toast.error(err.message); }, }); diff --git a/apps/dashboard/lib/trpc/routers/api/create.ts b/apps/dashboard/lib/trpc/routers/api/create.ts index 6748756dd2..5f18aaf05a 100644 --- a/apps/dashboard/lib/trpc/routers/api/create.ts +++ b/apps/dashboard/lib/trpc/routers/api/create.ts @@ -16,10 +16,17 @@ export const createApi = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ input, ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "We are unable to create an API. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/api/delete.ts b/apps/dashboard/lib/trpc/routers/api/delete.ts index 93f0d4ac07..6d39f97355 100644 --- a/apps/dashboard/lib/trpc/routers/api/delete.ts +++ b/apps/dashboard/lib/trpc/routers/api/delete.ts @@ -12,13 +12,21 @@ export const deleteApi = rateLimitedProcedure(ratelimit.delete) }), ) .mutation(async ({ ctx, input }) => { - const api = await db.query.apis.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.apiId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const api = await db.query.apis + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.apiId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to delete this API. Please contact support using support@unkey.dev", + }); + }); if (!api || api.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts b/apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts index e3f48f50f2..d9ba23a642 100644 --- a/apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts +++ b/apps/dashboard/lib/trpc/routers/api/updateDeleteProtection.ts @@ -13,13 +13,21 @@ export const updateAPIDeleteProtection = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ ctx, input }) => { - const api = await db.query.apis.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.apiId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const api = await db.query.apis + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.apiId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update the API. Please contact support using support@unkey.dev", + }); + }); if (!api || api.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts b/apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts index ad746d178e..028cb536c8 100644 --- a/apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts +++ b/apps/dashboard/lib/trpc/routers/api/updateIpWhitelist.ts @@ -28,13 +28,21 @@ export const updateApiIpWhitelist = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const api = await db.query.apis.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.apiId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const api = await db.query.apis + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.apiId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the API whitelist. Please contact support using support@unkey.dev", + }); + }); if (!api || api.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/api/updateName.ts b/apps/dashboard/lib/trpc/routers/api/updateName.ts index 7d6c85ba9b..35ccb48c4b 100644 --- a/apps/dashboard/lib/trpc/routers/api/updateName.ts +++ b/apps/dashboard/lib/trpc/routers/api/updateName.ts @@ -14,13 +14,21 @@ export const updateApiName = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ ctx, input }) => { - const api = await db.query.apis.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.apiId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const api = await db.query.apis + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.apiId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update the API name. Please contact support using support@unkey.dev.", + }); + }); if (!api || api.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/gateway/create.ts b/apps/dashboard/lib/trpc/routers/gateway/create.ts index f714ff15e4..1d8e3659c9 100644 --- a/apps/dashboard/lib/trpc/routers/gateway/create.ts +++ b/apps/dashboard/lib/trpc/routers/gateway/create.ts @@ -25,10 +25,18 @@ export const createGateway = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to create to create a gateway. Please contact support using support@unkey.dev.", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/key/create.ts b/apps/dashboard/lib/trpc/routers/key/create.ts index 5c5c34a66d..864fffb8e0 100644 --- a/apps/dashboard/lib/trpc/routers/key/create.ts +++ b/apps/dashboard/lib/trpc/routers/key/create.ts @@ -35,10 +35,18 @@ export const createKey = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to create a key for this API. Please contact support using support@unkey.dev.", + }); + }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", @@ -47,12 +55,20 @@ export const createKey = rateLimitedProcedure(ratelimit.create) }); } - const keyAuth = await db.query.keyAuth.findFirst({ - where: (table, { eq }) => eq(table.id, input.keyAuthId), - with: { - api: true, - }, - }); + const keyAuth = await db.query.keyAuth + .findFirst({ + where: (table, { eq }) => eq(table.id, input.keyAuthId), + with: { + api: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to create a key for this API. Please contact support using support@unkey.dev.", + }); + }); if (!keyAuth || keyAuth.workspaceId !== workspace.id) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/key/createRootKey.ts b/apps/dashboard/lib/trpc/routers/key/createRootKey.ts index 4f23f3dbc4..ad3ec44340 100644 --- a/apps/dashboard/lib/trpc/routers/key/createRootKey.ts +++ b/apps/dashboard/lib/trpc/routers/key/createRootKey.ts @@ -20,10 +20,18 @@ export const createRootKey = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ ctx, input }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to create a root key for this workspace. Please contact support using support@unkey.dev.", + }); + }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", @@ -32,12 +40,20 @@ export const createRootKey = rateLimitedProcedure(ratelimit.create) }); } - const unkeyApi = await db.query.apis.findFirst({ - where: eq(schema.apis.id, env().UNKEY_API_ID), - with: { - workspace: true, - }, - }); + const unkeyApi = await db.query.apis + .findFirst({ + where: eq(schema.apis.id, env().UNKEY_API_ID), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to create a rootkey for this workspace. Please contact support using support@unkey.dev.", + }); + }); if (!unkeyApi) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/key/delete.ts b/apps/dashboard/lib/trpc/routers/key/delete.ts index 51348260dd..edaca43a78 100644 --- a/apps/dashboard/lib/trpc/routers/key/delete.ts +++ b/apps/dashboard/lib/trpc/routers/key/delete.ts @@ -11,19 +11,27 @@ export const deleteKeys = rateLimitedProcedure(ratelimit.delete) }), ) .mutation(async ({ ctx, input }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - keys: { - where: (table, { and, inArray, isNull }) => - and(isNull(table.deletedAt), inArray(table.id, input.keyIds)), - columns: { - id: true, + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + keys: { + where: (table, { and, inArray, isNull }) => + and(isNull(table.deletedAt), inArray(table.id, input.keyIds)), + columns: { + id: true, + }, }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to delete this key. Please contact support using support@unkey.dev.", + }); + }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts b/apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts index 1c08336b19..61a27cbf18 100644 --- a/apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts +++ b/apps/dashboard/lib/trpc/routers/key/deleteRootKey.ts @@ -12,10 +12,18 @@ export const deleteRootKeys = rateLimitedProcedure(ratelimit.delete) }), ) .mutation(async ({ ctx, input }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to delete this root key. Please contact support using support@unkey.dev.", + }); + }); if (!workspace) { throw new TRPCError({ @@ -51,7 +59,7 @@ export const deleteRootKeys = rateLimitedProcedure(ratelimit.delete) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to delete the rootkey. Please contact support using support@unkey.dev", + "We are unable to delete the root key. Please contact support using support@unkey.dev", }); }); diff --git a/apps/dashboard/lib/trpc/routers/key/updateEnabled.ts b/apps/dashboard/lib/trpc/routers/key/updateEnabled.ts index b14bfe94c2..e8c68d3c70 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateEnabled.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateEnabled.ts @@ -12,13 +12,21 @@ export const updateKeyEnabled = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const key = await db.query.keys.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.keyId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const key = await db.query.keys + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.keyId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update enabled on this key. Please contact support using support@unkey.dev", + }); + }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/key/updateExpiration.ts b/apps/dashboard/lib/trpc/routers/key/updateExpiration.ts index 7886b4731c..76df731310 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateExpiration.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateExpiration.ts @@ -33,13 +33,21 @@ export const updateKeyExpiration = rateLimitedProcedure(ratelimit.update) } } - const key = await db.query.keys.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.keyId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const key = await db.query.keys + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.keyId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update expiration on this key. Please contact support using support@unkey.dev", + }); + }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: diff --git a/apps/dashboard/lib/trpc/routers/key/updateMetadata.ts b/apps/dashboard/lib/trpc/routers/key/updateMetadata.ts index 4bc208d5f1..b2f8c316fb 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateMetadata.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateMetadata.ts @@ -26,13 +26,21 @@ export const updateKeyMetadata = rateLimitedProcedure(ratelimit.update) }); } } - const key = await db.query.keys.findFirst({ - where: (table, { eq, isNull, and }) => - and(eq(table.id, input.keyId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const key = await db.query.keys + .findFirst({ + where: (table, { eq, isNull, and }) => + and(eq(table.id, input.keyId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update metadata on this key. Please contact support using support@unkey.dev", + }); + }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: diff --git a/apps/dashboard/lib/trpc/routers/key/updateName.ts b/apps/dashboard/lib/trpc/routers/key/updateName.ts index 0929d7d8dc..33ef712e23 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateName.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateName.ts @@ -14,13 +14,21 @@ export const updateKeyName = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const key = await db.query.keys.findFirst({ - where: (table, { eq, isNull, and }) => - and(eq(table.id, input.keyId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const key = await db.query.keys + .findFirst({ + where: (table, { eq, isNull, and }) => + and(eq(table.id, input.keyId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update the name on this key. Please contact support using support@unkey.dev", + }); + }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: diff --git a/apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts b/apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts index 2745763dcc..fa15f4fbcc 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateOwnerId.ts @@ -13,13 +13,21 @@ export const updateKeyOwnerId = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const key = await db.query.keys.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.keyId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const key = await db.query.keys + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.keyId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update ownerId on this key. Please contact support using support@unkey.dev", + }); + }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: diff --git a/apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts b/apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts index b02b61d598..3d20ca9331 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateRatelimit.ts @@ -16,13 +16,21 @@ export const updateKeyRatelimit = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const key = await db.query.keys.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.keyId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const key = await db.query.keys + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.keyId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update ratelimits on this key. Please contact support using support@unkey.dev", + }); + }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: diff --git a/apps/dashboard/lib/trpc/routers/key/updateRemaining.ts b/apps/dashboard/lib/trpc/routers/key/updateRemaining.ts index 6aecf13657..d0589f9988 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateRemaining.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateRemaining.ts @@ -27,13 +27,21 @@ export const updateKeyRemaining = rateLimitedProcedure(ratelimit.update) input.refill = undefined; } - const key = await db.query.keys.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.keyId), isNull(table.deletedAt)), - with: { - workspace: true, - }, - }); + const key = await db.query.keys + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.keyId), isNull(table.deletedAt)), + with: { + workspace: true, + }, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update remaining limits on this key. Please contact support using support@unkey.dev", + }); + }); if (!key || key.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ message: diff --git a/apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts b/apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts index 6e8102a80b..3d2db9049a 100644 --- a/apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts +++ b/apps/dashboard/lib/trpc/routers/key/updateRootKeyName.ts @@ -19,10 +19,18 @@ export const updateRootKeyName = t.procedure and(eq(table.id, input.keyId), isNull(table.deletedAt)), }); - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to update root key name. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ @@ -50,7 +58,7 @@ export const updateRootKeyName = t.procedure throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: - "We are unable to update name on this key. Please contact support using support@unkey.dev", + "We are unable to update root key name. Please contact support using support@unkey.dev", }); }); diff --git a/apps/dashboard/lib/trpc/routers/llmGateway/create.ts b/apps/dashboard/lib/trpc/routers/llmGateway/create.ts index eb2ee39c8f..b823a68fcd 100644 --- a/apps/dashboard/lib/trpc/routers/llmGateway/create.ts +++ b/apps/dashboard/lib/trpc/routers/llmGateway/create.ts @@ -13,10 +13,18 @@ export const createLlmGateway = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ input, ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We were unable to create LLM gateway. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", @@ -43,7 +51,10 @@ export const createLlmGateway = rateLimitedProcedure(ratelimit.create) "Gateway subdomains must have unique names. Please try a different subdomain.
If you believe this is an error and the subdomain should not be in use already, please contact support at support@unkey.dev", }); } - throw err; + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "Unable to create gateway, please contact support at support@unkey.dev", + }); }); await ingestAuditLogs({ diff --git a/apps/dashboard/lib/trpc/routers/llmGateway/delete.ts b/apps/dashboard/lib/trpc/routers/llmGateway/delete.ts index 3a1fec218f..32d1752e8a 100644 --- a/apps/dashboard/lib/trpc/routers/llmGateway/delete.ts +++ b/apps/dashboard/lib/trpc/routers/llmGateway/delete.ts @@ -8,17 +8,25 @@ import { rateLimitedProcedure, ratelimit } from "@/lib/trpc/ratelimitProcedure"; export const deleteLlmGateway = rateLimitedProcedure(ratelimit.delete) .input(z.object({ gatewayId: z.string() })) .mutation(async ({ ctx, input }) => { - const llmGateway = await db.query.llmGateways.findFirst({ - where: (table, { eq, and }) => and(eq(table.id, input.gatewayId)), - with: { - workspace: { - columns: { - id: true, - tenantId: true, + const llmGateway = await db.query.llmGateways + .findFirst({ + where: (table, { eq, and }) => and(eq(table.id, input.gatewayId)), + with: { + workspace: { + columns: { + id: true, + tenantId: true, + }, }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to delete LLM gateway. Please contact support using support@unkey.dev", + }); + }); if (!llmGateway || llmGateway.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/monitor/verification/create.ts b/apps/dashboard/lib/trpc/routers/monitor/verification/create.ts index b66754a1e2..cd2a7e601d 100644 --- a/apps/dashboard/lib/trpc/routers/monitor/verification/create.ts +++ b/apps/dashboard/lib/trpc/routers/monitor/verification/create.ts @@ -18,16 +18,26 @@ export const createVerificationMonitor = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ input, ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - keySpaces: { where: (table, { eq }) => eq(table.id, input.keySpaceId) }, - webhooks: { - where: (table, { eq }) => eq(table.destination, input.webhookUrl), + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + keySpaces: { + where: (table, { eq }) => eq(table.id, input.keySpaceId), + }, + webhooks: { + where: (table, { eq }) => eq(table.destination, input.webhookUrl), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create the reporter. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts b/apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts index 6438b49a1e..7850622b94 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/createNamespace.ts @@ -14,10 +14,18 @@ export const createNamespace = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ input, ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create a new namespace. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", @@ -42,7 +50,10 @@ export const createNamespace = rateLimitedProcedure(ratelimit.create) message: "duplicate namespace name. Please use a unique name for each namespace.", }); } - throw e; + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "We are unable to create namspace. Please contact support using support@unkey.dev", + }); } await ingestAuditLogs({ diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts b/apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts index 69ce306c62..bf9bf1cf65 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/createOverride.ts @@ -17,19 +17,27 @@ export const createOverride = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ input, ctx }) => { - const namespace = await db.query.ratelimitNamespaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.id, input.namespaceId), isNull(table.deletedAt)), - with: { - workspace: { - columns: { - id: true, - tenantId: true, - features: true, + const namespace = await db.query.ratelimitNamespaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.id, input.namespaceId), isNull(table.deletedAt)), + with: { + workspace: { + columns: { + id: true, + tenantId: true, + features: true, + }, }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create an override for this namespace. Please contact support using support@unkey.dev", + }); + }); if (!namespace || namespace.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts b/apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts index 8c939c0349..90b1a7d09b 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/deleteNamespace.ts @@ -12,19 +12,27 @@ export const deleteNamespace = rateLimitedProcedure(ratelimit.delete) }), ) .mutation(async ({ ctx, input }) => { - const namespace = await db.query.ratelimitNamespaces.findFirst({ - where: (table, { eq, and, isNull }) => - and(eq(table.id, input.namespaceId), isNull(table.deletedAt)), + const namespace = await db.query.ratelimitNamespaces + .findFirst({ + where: (table, { eq, and, isNull }) => + and(eq(table.id, input.namespaceId), isNull(table.deletedAt)), - with: { - workspace: { - columns: { - id: true, - tenantId: true, + with: { + workspace: { + columns: { + id: true, + tenantId: true, + }, }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to delete namespace. Please contact support using support@unkey.dev", + }); + }); if (!namespace || namespace.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts b/apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts index 1698fdc2a1..625ddb4c26 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/deleteOverride.ts @@ -12,24 +12,32 @@ export const deleteOverride = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ ctx, input }) => { - const override = await db.query.ratelimitOverrides.findFirst({ - where: (table, { and, eq, isNull }) => and(eq(table.id, input.id), isNull(table.deletedAt)), - with: { - namespace: { - columns: { - id: true, - }, - with: { - workspace: { - columns: { - id: true, - tenantId: true, + const override = await db.query.ratelimitOverrides + .findFirst({ + where: (table, { and, eq, isNull }) => and(eq(table.id, input.id), isNull(table.deletedAt)), + with: { + namespace: { + columns: { + id: true, + }, + with: { + workspace: { + columns: { + id: true, + tenantId: true, + }, }, }, }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to delete override for this namespace. Please contact support using support@unkey.dev", + }); + }); if (!override || override.namespace.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/updateNamespaceName.ts b/apps/dashboard/lib/trpc/routers/ratelimit/updateNamespaceName.ts index 703a090850..bae3131167 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/updateNamespaceName.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/updateNamespaceName.ts @@ -14,16 +14,24 @@ export const updateNamespaceName = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ ctx, input }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.id, input.workspaceId), isNull(table.deletedAt)), - with: { - ratelimitNamespaces: { - where: (table, { eq, and, isNull }) => - and(isNull(table.deletedAt), eq(schema.ratelimitNamespaces.id, input.namespaceId)), + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.id, input.workspaceId), isNull(table.deletedAt)), + with: { + ratelimitNamespaces: { + where: (table, { eq, and, isNull }) => + and(isNull(table.deletedAt), eq(schema.ratelimitNamespaces.id, input.namespaceId)), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the name for this namespace. Please contact support using support@unkey.dev", + }); + }); if (!ws || ws.tenantId !== ctx.tenant.id) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts b/apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts index c2f3f23cd8..b7097519fd 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/updateOverride.ts @@ -15,24 +15,32 @@ export const updateOverride = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ ctx, input }) => { - const override = await db.query.ratelimitOverrides.findFirst({ - where: (table, { and, eq, isNull }) => and(eq(table.id, input.id), isNull(table.deletedAt)), - with: { - namespace: { - columns: { - id: true, - }, - with: { - workspace: { - columns: { - id: true, - tenantId: true, + const override = await db.query.ratelimitOverrides + .findFirst({ + where: (table, { and, eq, isNull }) => and(eq(table.id, input.id), isNull(table.deletedAt)), + with: { + namespace: { + columns: { + id: true, + }, + with: { + workspace: { + columns: { + id: true, + tenantId: true, + }, }, }, }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update this override for this namespae. Please contact support using support@unkey.dev", + }); + }); if (!override || override.namespace.workspace.tenantId !== ctx.tenant.id) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/rbac/addPermissionToRootKey.ts b/apps/dashboard/lib/trpc/routers/rbac/addPermissionToRootKey.ts index f08810b0fd..149c10b452 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/addPermissionToRootKey.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/addPermissionToRootKey.ts @@ -22,10 +22,18 @@ export const addPermissionToRootKey = rateLimitedProcedure(ratelimit.create) }); } - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to add permission to the rootkey. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/rbac/connectPermissionToRole.ts b/apps/dashboard/lib/trpc/routers/rbac/connectPermissionToRole.ts index abad5c9dc4..02f77b4838 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/connectPermissionToRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/connectPermissionToRole.ts @@ -11,18 +11,26 @@ export const connectPermissionToRole = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - roles: { - where: (table, { eq }) => eq(table.id, input.roleId), + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + roles: { + where: (table, { eq }) => eq(table.id, input.roleId), + }, + permissions: { + where: (table, { eq }) => eq(table.id, input.permissionId), + }, }, - permissions: { - where: (table, { eq }) => eq(table.id, input.permissionId), - }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to connect this permission to role. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/rbac/connectRoleToKey.ts b/apps/dashboard/lib/trpc/routers/rbac/connectRoleToKey.ts index a7997ac333..10b13c913b 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/connectRoleToKey.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/connectRoleToKey.ts @@ -12,18 +12,26 @@ export const connectRoleToKey = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - roles: { - where: (table, { eq }) => eq(table.id, input.roleId), + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + roles: { + where: (table, { eq }) => eq(table.id, input.roleId), + }, + keys: { + where: (table, { eq }) => eq(table.id, input.keyId), + }, }, - keys: { - where: (table, { eq }) => eq(table.id, input.keyId), - }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to connect the role to the key. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/rbac/createPermission.ts b/apps/dashboard/lib/trpc/routers/rbac/createPermission.ts index 809f35d96c..240a683912 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/createPermission.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/createPermission.ts @@ -21,10 +21,18 @@ export const createPermission = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create permission. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/rbac/createRole.ts b/apps/dashboard/lib/trpc/routers/rbac/createRole.ts index e30504ea88..931d245119 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/createRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/createRole.ts @@ -22,10 +22,17 @@ export const createRole = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "We are unable to create role. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/rbac/deletePermission.ts b/apps/dashboard/lib/trpc/routers/rbac/deletePermission.ts index b3293c7d3b..371e243fd8 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/deletePermission.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/deletePermission.ts @@ -11,15 +11,23 @@ export const deletePermission = rateLimitedProcedure(ratelimit.delete) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - permissions: { - where: (table, { eq }) => eq(table.id, input.permissionId), + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + permissions: { + where: (table, { eq }) => eq(table.id, input.permissionId), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to delete this permission. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/rbac/deleteRole.ts b/apps/dashboard/lib/trpc/routers/rbac/deleteRole.ts index ec40236405..0e249a90a7 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/deleteRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/deleteRole.ts @@ -11,15 +11,22 @@ export const deleteRole = rateLimitedProcedure(ratelimit.delete) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - roles: { - where: (table, { eq }) => eq(table.id, input.roleId), + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + roles: { + where: (table, { eq }) => eq(table.id, input.roleId), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "We are unable to delete role. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/rbac/disconnectPermissionFromRole.ts b/apps/dashboard/lib/trpc/routers/rbac/disconnectPermissionFromRole.ts index 2596111431..5f9e8436d1 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/disconnectPermissionFromRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/disconnectPermissionFromRole.ts @@ -12,10 +12,18 @@ export const disconnectPermissionFromRole = rateLimitedProcedure(ratelimit.updat }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to remove permission from the role. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/rbac/disconnectRoleFromKey.ts b/apps/dashboard/lib/trpc/routers/rbac/disconnectRoleFromKey.ts index 1d27092af6..4a101c17ef 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/disconnectRoleFromKey.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/disconnectRoleFromKey.ts @@ -12,10 +12,18 @@ export const disconnectRoleFromKey = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to disconnect the role from the key. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/rbac/removePermissionFromRootKey.ts b/apps/dashboard/lib/trpc/routers/rbac/removePermissionFromRootKey.ts index 6628d1daff..90a9b67042 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/removePermissionFromRootKey.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/removePermissionFromRootKey.ts @@ -12,10 +12,18 @@ export const removePermissionFromRootKey = rateLimitedProcedure(ratelimit.update }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to remove permission from the root key. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ @@ -25,21 +33,29 @@ export const removePermissionFromRootKey = rateLimitedProcedure(ratelimit.update }); } - const key = await db.query.keys.findFirst({ - where: (table, { and, eq, isNull }) => - and( - eq(schema.keys.forWorkspaceId, workspace.id), - eq(schema.keys.id, input.rootKeyId), - isNull(table.deletedAt), - ), - with: { - permissions: { - with: { - permission: true, + const key = await db.query.keys + .findFirst({ + where: (table, { and, eq, isNull }) => + and( + eq(schema.keys.forWorkspaceId, workspace.id), + eq(schema.keys.id, input.rootKeyId), + isNull(table.deletedAt), + ), + with: { + permissions: { + with: { + permission: true, + }, }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to remove permission from the root key. Please contact support using support@unkey.dev", + }); + }); if (!key) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/rbac/updatePermission.ts b/apps/dashboard/lib/trpc/routers/rbac/updatePermission.ts index db19d599d6..fe1c3b9267 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/updatePermission.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/updatePermission.ts @@ -21,15 +21,23 @@ export const updatePermission = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - permissions: { - where: (table, { eq }) => eq(table.id, input.id), + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + permissions: { + where: (table, { eq }) => eq(table.id, input.id), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update permission. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/rbac/updateRole.ts b/apps/dashboard/lib/trpc/routers/rbac/updateRole.ts index 89fc880140..2787e57507 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/updateRole.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/updateRole.ts @@ -21,15 +21,23 @@ export const updateRole = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - roles: { - where: (table, { eq }) => eq(table.id, input.id), + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + roles: { + where: (table, { eq }) => eq(table.id, input.id), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the role. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ diff --git a/apps/dashboard/lib/trpc/routers/rbac/upsertPermission.ts b/apps/dashboard/lib/trpc/routers/rbac/upsertPermission.ts index c2006489c1..8a1d859335 100644 --- a/apps/dashboard/lib/trpc/routers/rbac/upsertPermission.ts +++ b/apps/dashboard/lib/trpc/routers/rbac/upsertPermission.ts @@ -10,9 +10,18 @@ export async function upsertPermission( name: string, ): Promise { return await db.transaction(async (tx) => { - const existingPermission = await tx.query.permissions.findFirst({ - where: (table, { and, eq }) => and(eq(table.workspaceId, workspaceId), eq(table.name, name)), - }); + const existingPermission = await tx.query.permissions + .findFirst({ + where: (table, { and, eq }) => + and(eq(table.workspaceId, workspaceId), eq(table.name, name)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to upsert the permission. Please contact support using support@unkey.dev", + }); + }); if (existingPermission) { return existingPermission; } diff --git a/apps/dashboard/lib/trpc/routers/secrets/create.ts b/apps/dashboard/lib/trpc/routers/secrets/create.ts index 750fd1fc1f..aa2ff1955b 100644 --- a/apps/dashboard/lib/trpc/routers/secrets/create.ts +++ b/apps/dashboard/lib/trpc/routers/secrets/create.ts @@ -17,10 +17,17 @@ export const createSecret = rateLimitedProcedure(ratelimit.create) }), ) .mutation(async ({ ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "We are unable to create secret. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/secrets/decrypt.ts b/apps/dashboard/lib/trpc/routers/secrets/decrypt.ts index d50861674d..1c46ffb01c 100644 --- a/apps/dashboard/lib/trpc/routers/secrets/decrypt.ts +++ b/apps/dashboard/lib/trpc/routers/secrets/decrypt.ts @@ -16,15 +16,23 @@ export const decryptSecret = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - secrets: { - where: (table, { eq }) => eq(table.id, input.secretId), + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + secrets: { + where: (table, { eq }) => eq(table.id, input.secretId), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to decrypt the secret. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/secrets/update.ts b/apps/dashboard/lib/trpc/routers/secrets/update.ts index f93d89993b..cd11b3ec13 100644 --- a/apps/dashboard/lib/trpc/routers/secrets/update.ts +++ b/apps/dashboard/lib/trpc/routers/secrets/update.ts @@ -15,15 +15,22 @@ export const updateSecret = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - secrets: { - where: (table, { eq }) => eq(table.id, input.secretId), + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + secrets: { + where: (table, { eq }) => eq(table.id, input.secretId), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "We are unable to update secret. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", @@ -60,7 +67,10 @@ export const updateSecret = rateLimitedProcedure(ratelimit.update) } if (Object.keys(update).length === 0) { - throw new TRPCError({ code: "PRECONDITION_FAILED", message: "No change detected" }); + throw new TRPCError({ + code: "PRECONDITION_FAILED", + message: "No change detected", + }); } await db diff --git a/apps/dashboard/lib/trpc/routers/webhook/create.ts b/apps/dashboard/lib/trpc/routers/webhook/create.ts index 50b59f7578..da78246de1 100644 --- a/apps/dashboard/lib/trpc/routers/webhook/create.ts +++ b/apps/dashboard/lib/trpc/routers/webhook/create.ts @@ -17,10 +17,18 @@ export const createWebhook = rateLimitedProcedure(ratelimit.create) ) .mutation(async ({ ctx }) => { const { UNKEY_WORKSPACE_ID, UNKEY_WEBHOOK_KEYS_API_ID } = env(); - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create a webhook. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", @@ -37,9 +45,17 @@ export const createWebhook = rateLimitedProcedure(ratelimit.create) prefix: "whsec", byteLength: 16, }); - const api = await db.query.apis.findFirst({ - where: (table, { eq }) => eq(table.id, UNKEY_WEBHOOK_KEYS_API_ID), - }); + const api = await db.query.apis + .findFirst({ + where: (table, { eq }) => eq(table.id, UNKEY_WEBHOOK_KEYS_API_ID), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create a webhook. Please contact support using support@unkey.dev", + }); + }); if (!api?.keyAuthId) { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", @@ -50,29 +66,56 @@ export const createWebhook = rateLimitedProcedure(ratelimit.create) const webhookId = newId("webhook"); const keyId = newId("key"); - await db.insert(schema.keys).values({ - id: keyId, - keyAuthId: api.keyAuthId, - hash, - start, - meta: JSON.stringify({ - webhookId, - }), - workspaceId: UNKEY_WORKSPACE_ID, - createdAt: new Date(), - }); + await db + .insert(schema.keys) + .values({ + id: keyId, + keyAuthId: api.keyAuthId, + hash, + start, + meta: JSON.stringify({ + webhookId, + }), + workspaceId: UNKEY_WORKSPACE_ID, + createdAt: new Date(), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create webhook. Please contact support using support@unkey.dev", + }); + }); const permissionId = newId("permission"); - await db.insert(schema.permissions).values({ - id: permissionId, - name: `webhook.${webhookId}.verify`, - workspaceId: UNKEY_WORKSPACE_ID, - }); - await db.insert(schema.keysPermissions).values({ - keyId, - permissionId, - workspaceId: UNKEY_WORKSPACE_ID, - }); + await db + .insert(schema.permissions) + .values({ + id: permissionId, + name: `webhook.${webhookId}.verify`, + workspaceId: UNKEY_WORKSPACE_ID, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create webhook. Please contact support using support@unkey.dev", + }); + }); + await db + .insert(schema.keysPermissions) + .values({ + keyId, + permissionId, + workspaceId: UNKEY_WORKSPACE_ID, + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to create webhook. Please contact support using support@unkey.dev", + }); + }); await ingestAuditLogs({ workspaceId: UNKEY_WORKSPACE_ID, diff --git a/apps/dashboard/lib/trpc/routers/webhook/delete.ts b/apps/dashboard/lib/trpc/routers/webhook/delete.ts index 3f9c303d43..e0b00eb4bb 100644 --- a/apps/dashboard/lib/trpc/routers/webhook/delete.ts +++ b/apps/dashboard/lib/trpc/routers/webhook/delete.ts @@ -11,15 +11,23 @@ export const deleteWebhook = rateLimitedProcedure(ratelimit.delete) }), ) .mutation(async ({ input, ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - webhooks: { - where: (table, { eq }) => eq(table.id, input.webhookId), + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + webhooks: { + where: (table, { eq }) => eq(table.id, input.webhookId), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to delete webhook. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/webhook/toggle.ts b/apps/dashboard/lib/trpc/routers/webhook/toggle.ts index 164bb288a4..edfd1403da 100644 --- a/apps/dashboard/lib/trpc/routers/webhook/toggle.ts +++ b/apps/dashboard/lib/trpc/routers/webhook/toggle.ts @@ -12,15 +12,23 @@ export const toggleWebhook = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ input, ctx }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - with: { - webhooks: { - where: (table, { eq }) => eq(table.id, input.webhookId), + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + with: { + webhooks: { + where: (table, { eq }) => eq(table.id, input.webhookId), + }, }, - }, - }); + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update webhook. Please contact support using support@unkey.dev", + }); + }); if (!ws) { throw new TRPCError({ code: "NOT_FOUND", diff --git a/apps/dashboard/lib/trpc/routers/workspace/changeName.ts b/apps/dashboard/lib/trpc/routers/workspace/changeName.ts index 577762c253..1820a4f277 100644 --- a/apps/dashboard/lib/trpc/routers/workspace/changeName.ts +++ b/apps/dashboard/lib/trpc/routers/workspace/changeName.ts @@ -13,10 +13,18 @@ export const changeWorkspaceName = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ ctx, input }) => { - const ws = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.id, input.workspaceId), isNull(table.deletedAt)), - }); + const ws = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.id, input.workspaceId), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to update the workspace name. Please contact support using support@unkey.dev", + }); + }); if (!ws || ws.tenantId !== ctx.tenant.id) { throw new Error("Workspace not found, Please sign back in and try again"); } diff --git a/apps/dashboard/lib/trpc/routers/workspace/changePlan.ts b/apps/dashboard/lib/trpc/routers/workspace/changePlan.ts index 2f6303e468..1182aa15fd 100644 --- a/apps/dashboard/lib/trpc/routers/workspace/changePlan.ts +++ b/apps/dashboard/lib/trpc/routers/workspace/changePlan.ts @@ -26,10 +26,17 @@ export const changeWorkspacePlan = rateLimitedProcedure(ratelimit.update) apiVersion: "2023-10-16", typescript: true, }); - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.id, input.workspaceId), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.id, input.workspaceId), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "We are unable to change plans. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ @@ -68,7 +75,14 @@ export const changeWorkspacePlan = rateLimitedProcedure(ratelimit.update) .set({ planDowngradeRequest: null, }) - .where(eq(schema.workspaces.id, input.workspaceId)); + .where(eq(schema.workspaces.id, input.workspaceId)) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable to change the plan on your workspace. Please contact support using support@unkey.dev", + }); + }); await ingestAuditLogs({ workspaceId: workspace.id, actor: { type: "user", id: ctx.user.id }, diff --git a/apps/dashboard/lib/trpc/routers/workspace/optIntoBeta.ts b/apps/dashboard/lib/trpc/routers/workspace/optIntoBeta.ts index 7ffa2b6ae1..74c7333bc5 100644 --- a/apps/dashboard/lib/trpc/routers/workspace/optIntoBeta.ts +++ b/apps/dashboard/lib/trpc/routers/workspace/optIntoBeta.ts @@ -11,10 +11,18 @@ export const optWorkspaceIntoBeta = rateLimitedProcedure(ratelimit.update) }), ) .mutation(async ({ ctx, input }) => { - const workspace = await db.query.workspaces.findFirst({ - where: (table, { and, eq, isNull }) => - and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), - }); + const workspace = await db.query.workspaces + .findFirst({ + where: (table, { and, eq, isNull }) => + and(eq(table.tenantId, ctx.tenant.id), isNull(table.deletedAt)), + }) + .catch((_err) => { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: + "We are unable opt you in to this beta feature. Please contact support using support@unkey.dev", + }); + }); if (!workspace) { throw new TRPCError({ diff --git a/apps/dashboard/lib/utils.ts b/apps/dashboard/lib/utils.ts index 1f01fc9551..02cac50d8a 100644 --- a/apps/dashboard/lib/utils.ts +++ b/apps/dashboard/lib/utils.ts @@ -5,8 +5,3 @@ export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } export const isBrowser = typeof window !== "undefined"; - -export function parseTrpcError(error: { message: string }): string { - const messages = JSON.parse(error.message) as Array<{ message: string }>; - return messages.at(0)?.message ?? "Unknown error, please contact support@unkey.dev"; -}