mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-01 19:59:35 -05:00
fix: prevent expected auth errors from being reported to Sentry (#7215)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -177,9 +177,9 @@ describe("utils.ts", () => {
|
||||
await expect(getEnvironmentAuth("env123")).rejects.toThrow("common.organization_not_found");
|
||||
});
|
||||
|
||||
test("throws error if membership not found", async () => {
|
||||
test("throws AuthorizationError if membership not found", async () => {
|
||||
vi.mocked(getMembershipByUserIdOrganizationId).mockResolvedValueOnce(null);
|
||||
await expect(getEnvironmentAuth("env123")).rejects.toThrow("common.membership_not_found");
|
||||
await expect(getEnvironmentAuth("env123")).rejects.toThrow(AuthorizationError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -481,7 +481,7 @@ describe("utils.ts", () => {
|
||||
await expect(getEnvironmentLayoutData("env123", "user123")).rejects.toThrow(AuthorizationError);
|
||||
});
|
||||
|
||||
test("throws error if membership not found", async () => {
|
||||
test("throws AuthorizationError if membership not found", async () => {
|
||||
vi.mocked(prisma.environment.findUnique).mockResolvedValueOnce({
|
||||
id: "env123",
|
||||
createdAt: new Date(),
|
||||
@@ -519,9 +519,7 @@ describe("utils.ts", () => {
|
||||
},
|
||||
} as any);
|
||||
|
||||
await expect(getEnvironmentLayoutData("env123", "user123")).rejects.toThrow(
|
||||
"common.membership_not_found"
|
||||
);
|
||||
await expect(getEnvironmentLayoutData("env123", "user123")).rejects.toThrow(AuthorizationError);
|
||||
});
|
||||
|
||||
test("fetches user before auth check, then environment data after authorization", async () => {
|
||||
|
||||
@@ -61,7 +61,7 @@ export const getEnvironmentAuth = reactCache(async (environmentId: string): Prom
|
||||
|
||||
const currentUserMembership = await getMembershipByUserIdOrganizationId(session?.user.id, organization.id);
|
||||
if (!currentUserMembership) {
|
||||
throw new Error(t("common.membership_not_found"));
|
||||
throw new AuthorizationError(t("common.membership_not_found"));
|
||||
}
|
||||
|
||||
const { isMember, isOwner, isManager, isBilling } = getAccessFlags(currentUserMembership?.role);
|
||||
@@ -293,7 +293,7 @@ export const getEnvironmentLayoutData = reactCache(
|
||||
|
||||
// Validate user's membership was found
|
||||
if (!membership) {
|
||||
throw new Error(t("common.membership_not_found"));
|
||||
throw new AuthorizationError(t("common.membership_not_found"));
|
||||
}
|
||||
|
||||
// Fetch remaining data in parallel
|
||||
|
||||
Reference in New Issue
Block a user