Skip to content

Commit 89f3bdb

Browse files
committed
feat: use orpc interceptor for demo
1 parent 44ae0c6 commit 89f3bdb

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

app/lib/orpc/client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
import { createORPCClient } from '@orpc/client';
1+
import { createORPCClient, onError, ORPCError } from '@orpc/client';
22
import { RPCLink } from '@orpc/client/fetch';
33
import { createORPCReactQueryUtils } from '@orpc/react-query';
44
import type { RouterClient } from '@orpc/server';
55

66
import { envClient } from '@/env/client';
7+
import { openDemoModeDrawer } from '@/features/demo-mode/demo-mode-drawer';
78

89
import type { Router } from './types';
910

1011
const link = new RPCLink({
1112
url: `${envClient.VITE_BASE_URL}/api/rpc`,
13+
interceptors: [
14+
onError((error) => {
15+
if (error instanceof ORPCError && error.message === 'DEMO_MODE_ENABLED') {
16+
openDemoModeDrawer();
17+
}
18+
}),
19+
],
1220
});
1321

1422
const orpcClient: RouterClient<Router> = createORPCClient(link);
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { ORPCError } from '@orpc/client';
2-
import { MutationCache, QueryClient } from '@tanstack/react-query';
3-
4-
import { openDemoModeDrawer } from '@/features/demo-mode/demo-mode-drawer';
1+
import { QueryClient } from '@tanstack/react-query';
52

63
const networkMode = import.meta.dev ? 'always' : undefined;
74

@@ -14,11 +11,4 @@ export const queryClient = new QueryClient({
1411
networkMode,
1512
},
1613
},
17-
mutationCache: new MutationCache({
18-
onError: (error) => {
19-
if (error instanceof ORPCError && error.message === 'DEMO_MODE_ENABLED') {
20-
openDemoModeDrawer();
21-
}
22-
},
23-
}),
2414
});

0 commit comments

Comments
 (0)