mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 08:46:22 +02:00
feat: enhance error handling with PostHog integration
- Added PostHog error capturing for non-authentication errors in BaseApiService. - Refactored PostHog client initialization to ensure a single instance is used across the application.
This commit is contained in:
parent
9f17d834f6
commit
1ab395a34e
5 changed files with 122 additions and 8 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import posthog from "posthog-js";
|
||||
import type { ZodType } from "zod";
|
||||
import { getBearerToken, handleUnauthorized, refreshAccessToken } from "../auth-utils";
|
||||
import { AppError, AuthenticationError, AuthorizationError, NotFoundError } from "../error";
|
||||
|
|
@ -231,6 +232,20 @@ class BaseApiService {
|
|||
return data;
|
||||
} catch (error) {
|
||||
console.error("Request failed:", JSON.stringify(error));
|
||||
if (!(error instanceof AuthenticationError)) {
|
||||
try {
|
||||
posthog.captureException(error, {
|
||||
api_url: url,
|
||||
api_method: options?.method ?? "GET",
|
||||
...(error instanceof AppError && {
|
||||
status_code: error.status,
|
||||
status_text: error.statusText,
|
||||
}),
|
||||
});
|
||||
} catch {
|
||||
// PostHog capture failed — don't block the error flow
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue