Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add api error analytics #5925

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/common/persistence.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister';
import { QueryCache, QueryClient } from '@tanstack/react-query';
import { persistQueryClient } from '@tanstack/react-query-persist-client';
import { isAxiosError } from 'axios';
import { ZodError } from 'zod';

import { PERSISTENCE_CACHE_TIME } from '@leather.io/constants';
Expand All @@ -11,10 +12,10 @@

const storage = {
getItem: async (key: string) => {
const storageVal = await chrome.storage.local.get(key);

Check warning on line 15 in src/app/common/persistence.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'chrome' is deprecated. Part of the deprecated Chrome Apps platform
return storageVal[key];
},
setItem: (key: string, value: string) => chrome.storage.local.set({ [key]: value }),

Check warning on line 18 in src/app/common/persistence.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'chrome' is deprecated. Part of the deprecated Chrome Apps platform
removeItem: (key: string) => chrome.storage.local.remove([key]),
};

Expand All @@ -28,6 +29,16 @@
export const queryClient = new QueryClient({
queryCache: new QueryCache({
onError(error, query) {
if (isAxiosError(error)) {
const errorReport = {
statusCode: error.response?.status,
query: query.queryKey[0],
hash: query.queryHash,
error: error.toJSON(),
};
void analytics.track('api_error', errorReport);
}

if (isZodError(error)) {
const zodErrorReport = {
query: query.queryKey[0],
Expand Down
Loading