fix: prevent expected auth errors from being reported to Sentry (#7215)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Theodór Tómas
2026-02-11 15:43:08 +07:00
committed by GitHub
parent 48eff5b547
commit a5c92bbc7b
7 changed files with 305 additions and 37 deletions
@@ -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 () => {
+2 -2
View File
@@ -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