mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-02 22:01:05 +02:00
feat: dynamic import of PostHog
This commit is contained in:
parent
fc4f9ba7c0
commit
0a65aa1a31
2 changed files with 20 additions and 14 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import posthog from "posthog-js";
|
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export default function ErrorPage({
|
export default function ErrorPage({
|
||||||
|
|
@ -11,7 +11,11 @@ export default function ErrorPage({
|
||||||
reset: () => void;
|
reset: () => void;
|
||||||
}) {
|
}) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
posthog.captureException(error);
|
import("posthog-js")
|
||||||
|
.then(({ default: posthog }) => {
|
||||||
|
posthog.captureException(error);
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import posthog from "posthog-js";
|
|
||||||
import type { ZodType } from "zod";
|
import type { ZodType } from "zod";
|
||||||
import { getBearerToken, handleUnauthorized, refreshAccessToken } from "../auth-utils";
|
import { getBearerToken, handleUnauthorized, refreshAccessToken } from "../auth-utils";
|
||||||
import { AppError, AuthenticationError, AuthorizationError, NotFoundError } from "../error";
|
import { AppError, AuthenticationError, AuthorizationError, NotFoundError } from "../error";
|
||||||
|
|
@ -234,18 +233,21 @@ class BaseApiService {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Request failed:", JSON.stringify(error));
|
console.error("Request failed:", JSON.stringify(error));
|
||||||
if (!(error instanceof AuthenticationError)) {
|
if (!(error instanceof AuthenticationError)) {
|
||||||
try {
|
import("posthog-js")
|
||||||
posthog.captureException(error, {
|
.then(({ default: posthog }) => {
|
||||||
api_url: url,
|
posthog.captureException(error, {
|
||||||
api_method: options?.method ?? "GET",
|
api_url: url,
|
||||||
...(error instanceof AppError && {
|
api_method: options?.method ?? "GET",
|
||||||
status_code: error.status,
|
...(error instanceof AppError && {
|
||||||
status_text: error.statusText,
|
status_code: error.status,
|
||||||
}),
|
status_text: error.statusText,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
// PostHog is not available in the current environment
|
||||||
|
console.error("Failed to capture exception in PostHog");
|
||||||
});
|
});
|
||||||
} catch {
|
|
||||||
// PostHog capture failed — don't block the error flow
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue