Skip to content

Commit

Permalink
Merge pull request #1560 from Shelf-nu/improve-sentry-tracking
Browse files Browse the repository at this point in the history
improvement: turn off capturing or certain errors that are handled already
  • Loading branch information
DonKoko authored Jan 7, 2025
2 parents c98aa07 + da800c3 commit 76eab81
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/modules/auth/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export async function signInWithSSO(domain: string) {
// @ts-expect-error
if (cause?.code === "sso_provider_not_found") {
message = "No SSO provider assigned for your organization's domain";
shouldBeCaptured = false;
}

throw new ShelfError({
Expand Down
1 change: 1 addition & 0 deletions app/modules/custom-field/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export async function upsertCustomField(
},
},
label,
shouldBeCaptured: false,
});
}
if (existingCustomField.type === "OPTION") {
Expand Down
2 changes: 2 additions & 0 deletions app/modules/invite/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async function validateInvite(
"This email domain uses SCIM SSO for this workspace. Users are managed automatically through your identity provider.",
label: "Invite",
status: 400,
shouldBeCaptured: false,
});
}

Expand All @@ -59,6 +60,7 @@ async function validateInvite(
"This email domain uses SSO authentication. The user needs to sign up via SSO before they can be invited.",
label: "Invite",
status: 400,
shouldBeCaptured: false,
});
}
}
Expand Down
11 changes: 6 additions & 5 deletions app/modules/location/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ export async function getLocation(
} catch (cause) {
throw new ShelfError({
cause,
message: "Something went wrong while fetching location",
title: "Location not found",
message:
"The location you are trying to access does not exist or you do not have permission to access it.",
additionalData: {
...params,
id,
organizationId,
...(isLikeShelfError(cause) ? cause.additionalData : {}),
},
label,
shouldBeCaptured: isLikeShelfError(cause)
? cause.shouldBeCaptured
: !isNotFoundError(cause),
shouldBeCaptured: !isNotFoundError(cause),
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion app/routes/_auth+/resend-otp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export async function action({ request }: ActionFunctionArgs) {

throw notAllowedMethod(method);
} catch (cause) {
const reason = makeShelfError(cause);
//@ts-expect-error
const isRateLimitError = cause.code === "over_email_send_rate_limit";

const reason = makeShelfError(cause, {}, !isRateLimitError);
return json(error(reason), { status: reason.status });
}
}
13 changes: 12 additions & 1 deletion app/routes/_layout+/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Roles } from "@prisma/client";
import type { LinksFunction, LoaderFunctionArgs } from "@remix-run/node";
import type {
LinksFunction,
LoaderFunctionArgs,
MetaFunction,
} from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Link, NavLink, Outlet, useLoaderData } from "@remix-run/react";
import { useAtomValue } from "jotai";
Expand All @@ -24,6 +28,7 @@ import { config } from "~/config/shelf.config";
import { getSelectedOrganisation } from "~/modules/organization/context.server";
import { getUserByID } from "~/modules/user/service.server";
import styles from "~/styles/layout/index.css?url";
import { appendToMetaTitle } from "~/utils/append-to-meta-title";
import {
installPwaPromptCookie,
initializePerPageCookieOnLayout,
Expand Down Expand Up @@ -137,6 +142,12 @@ export async function loader({ context, request }: LoaderFunctionArgs) {
}
}

export const meta: MetaFunction<typeof loader> = ({ error }) => [
/** This will make sure that if we have an error its visible in the title of the browser tab */
// @ts-expect-error
{ title: error ? appendToMetaTitle(error.data.error.title) : "" },
];

export default function App() {
useCrisp();
const { disabledTeamOrg, minimizedSidebar } = useLoaderData<typeof loader>();
Expand Down
1 change: 1 addition & 0 deletions app/routes/_layout+/settings.custom-fields.new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export async function loader({ context, request }: LoaderFunctionArgs) {
);
} catch (cause) {
const reason = makeShelfError(cause, { userId });

throw json(error(reason), { status: reason.status });
}
}
Expand Down
1 change: 1 addition & 0 deletions app/routes/qr+/$qrId_.link.asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const loader = async ({
label: "QR",
status: 403,
cause: null,
shouldBeCaptured: false,
});
}

Expand Down
1 change: 1 addition & 0 deletions app/routes/qr+/$qrId_.link.kit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const loader = async ({
label: "QR",
status: 403,
cause: null,
shouldBeCaptured: false,
});
}

Expand Down
1 change: 1 addition & 0 deletions app/utils/custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const buildCustomFieldValue = (
: "Invalid custom field value",
message: `Failed to read/process custom field value for '${def.name}' with type '${def.type}'. The value we found is: '${value.raw}'. Make sure to format your dates using the format: YYYY-MM-DD`,
label: "Custom fields",
shouldBeCaptured: false,
});
}
};
Expand Down
5 changes: 3 additions & 2 deletions app/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ export function makeShelfError(
...cause.additionalData,
...additionalData,
},
shouldBeCaptured: cause.shouldBeCaptured || shouldBeCaptured,
shouldBeCaptured:
"shouldBeCaptured" in cause ? cause.shouldBeCaptured : shouldBeCaptured,
});
}

Expand Down Expand Up @@ -312,7 +313,7 @@ export function maybeUniqueConstraintViolation(
options?: Options
) {
let message = `We could not create or update this ${modelName}. Please try again or contact support.`;
let shouldBeCaptured = true;
let shouldBeCaptured = false;
const validationErrors = {} as ValidationError<any>;

if (
Expand Down
5 changes: 5 additions & 0 deletions app/utils/storage.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ export async function uploadImageFromUrl(
message: "Failed to fetch image from URL",
additionalData: { imageUrl },
label,
shouldBeCaptured: false,
});
});

if (!response.ok) {
throw new ShelfError({
cause: null,
message: "Failed to fetch image from URL",
shouldBeCaptured: false,
additionalData: { imageUrl, status: response.status },
label,
});
Expand All @@ -245,6 +247,7 @@ export async function uploadImageFromUrl(
message: "URL does not point to a valid image",
additionalData: { imageUrl, contentType: actualContentType },
label,
shouldBeCaptured: false,
});
}

Expand All @@ -257,6 +260,7 @@ export async function uploadImageFromUrl(
}MB`,
additionalData: { imageUrl, size: imageBlob.size },
label,
shouldBeCaptured: false,
});
}

Expand Down Expand Up @@ -308,6 +312,7 @@ export async function uploadImageFromUrl(
: "Failed to process and upload image from URL",
additionalData: { imageUrl, filename, contentType, bucketName },
label,
shouldBeCaptured: isShelfError ? cause.shouldBeCaptured : true,
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/utils/subscription.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export async function assertUserCanCreateMoreOrganizations(userId: string) {
message: "You cannot create more workspaces with your current plan.",
additionalData: { userId, tierLimit },
label,
shouldBeCaptured: false,
});
}
}
Expand Down Expand Up @@ -360,6 +361,7 @@ export async function assertUserCanInviteUsersToWorkspace({
"You cannot invite other users to a personal workspace. Please create a Team workspace.",
status: 403,
label,
shouldBeCaptured: false,
});
}
}
Expand Down

0 comments on commit 76eab81

Please sign in to comment.