fix: Redact prisma errors (#10536)

This commit is contained in:
Hariom Balhara authored and GitHub committed 2023-08-03 16:22:38 +01:00
1 parent 669065cebd
commit 5491821baf
8 files changed
+96 -16

No files matched your search

+7 -1
View File
@@ -1,6 +1,8 @@
import * as Sentry from "@sentry/nextjs";
import type { NextMiddleware } from "next-api-middleware";
import { redactError } from "@calcom/lib/redactError";
export const captureErrors: NextMiddleware = async (_req, res, next) => {
try {
// Catch any errors that are thrown in remaining
@@ -8,7 +10,11 @@ export const captureErrors: NextMiddleware = async (_req, res, next) => {
await next();
} catch (error) {
Sentry.captureException(error);
console.log(error);
const redactedError = redactError(error);
if (redactedError instanceof Error) {
res.status(400).json({ message: redactedError.message, error: redactedError });
return;
}
res.status(400).json({ message: "Something went wrong", error });
}
};
+10 -3
View File
@@ -28,10 +28,17 @@ const withMiddleware = label(
customPrismaClient,
extendRequest,
pagination: withPagination,
sentry: captureErrors,
captureErrors,
},
// The order here, determines the order of execution, put customPrismaClient before verifyApiKey always.
["extendRequest", "sentry", "customPrismaClient", "verifyApiKey", "addRequestId"] // <-- Provide a list of middleware to call automatically
// The order here, determines the order of execution
[
"extendRequest",
"captureErrors",
// - Put customPrismaClient before verifyApiKey always.
"customPrismaClient",
"verifyApiKey",
"addRequestId",
] // <-- Provide a list of middleware to call automatically
);
export { withMiddleware };