Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(redwood): fix incorrect error type thrown #1659

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/misc/redwood/src/graphql.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -47,7 +46,7 @@ export function useZenStack<PrismaClient extends object>(

// 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
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/enhancements/policy/policy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ class RequestHandler extends APIHandlerBase {

private handlePrismaError(err: unknown) {
if (isPrismaClientKnownRequestError(err)) {
if (err.code === PrismaErrorCode.CONSTRAINED_FAILED) {
if (err.code === PrismaErrorCode.CONSTRAINT_FAILED) {
if (err.meta?.reason === CrudFailureReason.DATA_VALIDATION_VIOLATION) {
return this.makeError(
'validationError',
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { logError, registerCustomSerializers } from '../utils';
registerCustomSerializers();

const ERROR_STATUS_MAPPING: Record<string, number> = {
[PrismaErrorCode.CONSTRAINED_FAILED]: 403,
[PrismaErrorCode.CONSTRAINT_FAILED]: 403,
[PrismaErrorCode.REQUIRED_CONNECTED_RECORD_NOT_FOUND]: 404,
[PrismaErrorCode.DEPEND_ON_RECORD_NOT_FOUND]: 404,
};
Expand Down
Loading