Skip to content

Commit 796b13d

Browse files
committed
Add toast error for too many requests
1 parent 8197863 commit 796b13d

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

web/lib/api.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { API, APIParams, APIPath } from 'common/api/schema'
2-
import { typedAPICall } from 'common/util/api'
3-
import { sleep } from 'common/util/time'
4-
import { auth } from './firebase/users'
5-
export { APIError } from 'common/api/utils'
1+
import {API, APIParams, APIPath} from 'common/api/schema'
2+
import {typedAPICall} from 'common/util/api'
3+
import {sleep} from 'common/util/time'
4+
import {auth} from './firebase/users'
5+
import toast from "react-hot-toast";
6+
import {APIError} from "common/api/utils";
67

78
export async function api<P extends APIPath>(
89
path: P,
@@ -21,7 +22,12 @@ export async function api<P extends APIPath>(
2122
}
2223
}
2324

24-
return typedAPICall(path, params, auth.currentUser)
25+
try {
26+
return typedAPICall(path, params, auth.currentUser)
27+
} catch (e) {
28+
if (e instanceof APIError && e.code === 429) toast.error('Too many requests. Please try again later.')
29+
throw e
30+
}
2531
}
2632

2733
function curriedAPI<P extends APIPath>(path: P) {

0 commit comments

Comments
 (0)