Skip to content

Commit

Permalink
Log exceptions on ErrorPage (#1173)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Dec 17, 2024
1 parent 6650fbe commit 8fba709
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 10 additions & 10 deletions packages/keychain/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { PropsWithChildren } from "react";
import React, { PropsWithChildren, useEffect } from "react";
import { Container, Content, Footer } from "./layout";
import { AlertIcon, ExternalIcon } from "@cartridge/ui";
import { Button, HStack, Link, Text } from "@chakra-ui/react";
import { useConnection } from "hooks/connection";
import NextLink from "next/link";
import { CARTRIDGE_DISCORD_LINK } from "const";
import posthog from "posthog-js";
import { usePostHog } from "posthog-js/react";

export class ErrorBoundary extends React.Component<
PropsWithChildren,
Expand All @@ -20,14 +20,6 @@ export class ErrorBoundary extends React.Component<
return { error };
}

componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.log({ error, errorInfo });
posthog?.captureException(error, {
info: errorInfo,
source: "ErrorBoundary",
});
}

render() {
if (this.state.error) {
return <ErrorPage error={this.state.error} />;
Expand All @@ -40,6 +32,14 @@ export class ErrorBoundary extends React.Component<
export function ErrorPage({ error }: { error: Error }) {
const { closeModal } = useConnection();

const posthog = usePostHog();

useEffect(() => {
posthog?.captureException(error, {
source: "ErrorPage",
});
}, [error, posthog]);

return (
<Container
variant="expanded"
Expand Down
4 changes: 3 additions & 1 deletion packages/keychain/src/hooks/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ export function useConnectionValue() {
setChainId(chainId);
} catch (e) {
console.error(e);
setError(new Error("Unable to fetch Chain ID from provided RPC URL"));
setError(
new Error(`Unable to fetch Chain ID from provided RPC URL: ${e}`),
);
}
};

Expand Down

0 comments on commit 8fba709

Please sign in to comment.