Skip to content

Commit

Permalink
feat: add error analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Oct 29, 2024
1 parent 27e05c4 commit 8625fe7
Showing 1 changed file with 11 additions and 0 deletions.
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 Down Expand Up @@ -28,6 +29,16 @@ function isZodError(error: Error): error is ZodError {
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

0 comments on commit 8625fe7

Please sign in to comment.