diff --git a/packages/app-store/_utils/stripe.types.ts b/packages/app-store/_utils/stripe.types.ts deleted file mode 100644 index d9f6a04692..0000000000 --- a/packages/app-store/_utils/stripe.types.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { z } from "zod"; - -// Copied from node_modules/stripe/types/Errors.d.ts because stripe lib doesn't expose these types -// Ref: https://github.com/stripe/stripe-node/blob/master/types/Errors.d.ts#L194 -interface StripeInvalidRequestError extends Error { - readonly type: "StripeInvalidRequestError"; - readonly rawType: "invalid_request_error"; - /** - * A human-readable message giving more details about the error. For card errors, these messages can - * be shown to your users. - */ - readonly message: string; - /** - * For card errors, a short string describing the kind of card error that occurred. - * - * @docs https://stripe.com/docs/error-codes - */ - readonly code?: string; - - /** - * A URL to more information about the error code reported. - * - * @docs https://stripe.com/docs/error-codes - */ - readonly doc_url?: string; - - /** - * Typically a 4xx or 5xx. - */ - readonly statusCode?: number; - - readonly raw: unknown; - - readonly headers: { - [key: string]: string; - }; - - readonly requestId: string; - - /** - * The parameter the error relates to if the error is parameter-specific. You can use this to display a - * message near the correct form field, for example. - */ - readonly param?: string; -} - -const errorSchema = z.object({ - name: z.string(), - message: z.string(), - stack: z.string().optional(), -}); - -export const stripeInvalidRequestErrorSchema = errorSchema.extend({ - type: z.literal("StripeInvalidRequestError"), - rawType: z.literal("invalid_request_error"), - code: z.string().optional(), - doc_url: z.string().optional(), - statusCode: z.number().optional(), - raw: z.unknown(), - headers: z.record(z.string()), - requestId: z.string(), - param: z.string().optional(), -}); diff --git a/packages/lib/server/getServerErrorFromUnknown.ts b/packages/lib/server/getServerErrorFromUnknown.ts index cf82fd4912..b7aecab65f 100644 --- a/packages/lib/server/getServerErrorFromUnknown.ts +++ b/packages/lib/server/getServerErrorFromUnknown.ts @@ -2,7 +2,6 @@ import { Prisma } from "@prisma/client"; import type { ZodIssue } from "zod"; import { ZodError } from "zod"; -import { stripeInvalidRequestErrorSchema } from "@calcom/app-store/_utils/stripe.types"; import { ErrorCode } from "@calcom/lib/errorCodes"; import { ErrorWithCode } from "@calcom/lib/errors"; @@ -11,6 +10,7 @@ import { getHTTPStatusCodeFromError } from "@trpc/server/http"; import { HttpError } from "../http-error"; import { redactError } from "../redactError"; +import { stripeInvalidRequestErrorSchema } from "../stripe-error"; function hasName(cause: unknown): cause is { name: string } { return !!cause && typeof cause === "object" && "name" in cause; diff --git a/packages/lib/stripe-error.ts b/packages/lib/stripe-error.ts new file mode 100644 index 0000000000..6e5728f37c --- /dev/null +++ b/packages/lib/stripe-error.ts @@ -0,0 +1,19 @@ +import { z } from "zod"; + +const errorSchema = z.object({ + name: z.string(), + message: z.string(), + stack: z.string().optional(), +}); + +export const stripeInvalidRequestErrorSchema = errorSchema.extend({ + type: z.literal("StripeInvalidRequestError"), + rawType: z.literal("invalid_request_error"), + code: z.string().optional(), + doc_url: z.string().optional(), + statusCode: z.number().optional(), + raw: z.unknown(), + headers: z.record(z.string()), + requestId: z.string(), + param: z.string().optional(), +});