mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-13 19:17:15 -04:00
Add toast error for too many requests
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { API, APIParams, APIPath } from 'common/api/schema'
|
||||
import { typedAPICall } from 'common/util/api'
|
||||
import { sleep } from 'common/util/time'
|
||||
import { auth } from './firebase/users'
|
||||
export { APIError } from 'common/api/utils'
|
||||
import {API, APIParams, APIPath} from 'common/api/schema'
|
||||
import {typedAPICall} from 'common/util/api'
|
||||
import {sleep} from 'common/util/time'
|
||||
import {auth} from './firebase/users'
|
||||
import toast from "react-hot-toast";
|
||||
import {APIError} from "common/api/utils";
|
||||
|
||||
export async function api<P extends APIPath>(
|
||||
path: P,
|
||||
@@ -21,7 +22,12 @@ export async function api<P extends APIPath>(
|
||||
}
|
||||
}
|
||||
|
||||
return typedAPICall(path, params, auth.currentUser)
|
||||
try {
|
||||
return typedAPICall(path, params, auth.currentUser)
|
||||
} catch (e) {
|
||||
if (e instanceof APIError && e.code === 429) toast.error('Too many requests. Please try again later.')
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
function curriedAPI<P extends APIPath>(path: P) {
|
||||
|
||||
Reference in New Issue
Block a user