From 5bfd695e59ba65f10497d658b663dac43ace47b7 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 23 Aug 2024 21:05:25 -0700 Subject: [PATCH] fix(redwood): fix incorrect error type thrown --- packages/misc/redwood/src/graphql.ts | 5 ++--- packages/runtime/src/constants.ts | 2 +- packages/runtime/src/enhancements/policy/policy-utils.ts | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/misc/redwood/src/graphql.ts b/packages/misc/redwood/src/graphql.ts index 69267b5e2..943329744 100644 --- a/packages/misc/redwood/src/graphql.ts +++ b/packages/misc/redwood/src/graphql.ts @@ -1,9 +1,8 @@ -import { ForbiddenError } from '@redwoodjs/graphql-server'; +import { ForbiddenError, ValidationError } from '@redwoodjs/graphql-server'; import { CrudFailureReason, EnhancementOptions, PrismaErrorCode, - ValidationError, enhance, isPrismaClientKnownRequestError, type AuthUser, @@ -47,7 +46,7 @@ export function useZenStack( // Transforms ZenStack errors into appropriate RedwoodJS errors function transformError(error: unknown) { - if (isPrismaClientKnownRequestError(error) && error.code === PrismaErrorCode.CONSTRAINED_FAILED) { + if (isPrismaClientKnownRequestError(error) && error.code === PrismaErrorCode.CONSTRAINT_FAILED) { if ( error.meta?.reason === CrudFailureReason.ACCESS_POLICY_VIOLATION || error.meta?.reason === CrudFailureReason.RESULT_NOT_READABLE diff --git a/packages/runtime/src/constants.ts b/packages/runtime/src/constants.ts index 5fd8c2901..36acf8c83 100644 --- a/packages/runtime/src/constants.ts +++ b/packages/runtime/src/constants.ts @@ -40,7 +40,7 @@ export enum PrismaErrorCode { /** * A constraint failed on the database */ - CONSTRAINED_FAILED = 'P2004', + CONSTRAINT_FAILED = 'P2004', /** * The required connected records were not found diff --git a/packages/runtime/src/enhancements/policy/policy-utils.ts b/packages/runtime/src/enhancements/policy/policy-utils.ts index f01bebd52..2df2ea2e2 100644 --- a/packages/runtime/src/enhancements/policy/policy-utils.ts +++ b/packages/runtime/src/enhancements/policy/policy-utils.ts @@ -1215,7 +1215,7 @@ export class PolicyUtil extends QueryUtils { reason?: CrudFailureReason, zodErrors?: ZodError ) { - const args: any = { clientVersion: getVersion(), code: PrismaErrorCode.CONSTRAINED_FAILED, meta: {} }; + const args: any = { clientVersion: getVersion(), code: PrismaErrorCode.CONSTRAINT_FAILED, meta: {} }; if (reason) { args.meta.reason = reason; }