Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
57 lines (51 loc) · 1.58 KB

File metadata and controls

57 lines (51 loc) · 1.58 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { QueryClient, QueryCache, MutationCache } from '@tanstack/react-query'
import { isApiError, getErrorMessage } from './api/client'
type ErrorHandler = (message: string) => void
let globalErrorHandler: ErrorHandler = (message) => {
// Fallback: log to console if no handler is registered
console.error('[API Error]', message)
}
export function setGlobalErrorHandler(handler: ErrorHandler) {
globalErrorHandler = handler
}
function handleError(error: unknown) {
const message = getErrorMessage(error)
globalErrorHandler(message)
}
function shouldRetry(failureCount: number, error: unknown): boolean {
// Don't retry on client errors (4xx) except for rate limiting (429)
if (isApiError(error)) {
if (error.status >= 400 && error.status < 500 && error.status !== 429) {
return false
}
}
// Retry up to 2 times for network/server errors
return failureCount < 2
}
export const queryClient = new QueryClient({
queryCache: new QueryCache({
onError: (error, query) => {
// Only show error toast if the query has already been successful before
// (this avoids showing errors during initial load)
if (query.state.data !== undefined) {
handleError(error)
}
},
}),
mutationCache: new MutationCache({
onError: (error) => {
// Always show errors for mutations
handleError(error)
},
}),
defaultOptions: {
queries: {
staleTime: 1000 * 60, // 1 minute
refetchOnWindowFocus: false,
retry: shouldRetry,
},
mutations: {
retry: false, // Don't retry mutations by default
},
},
})
Morty Proxy This is a proxified and sanitized view of the page, visit original site.