From 796b13dd621b4fc0e0409cde5fa8171fa32bda42 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Wed, 15 Oct 2025 23:47:01 +0200 Subject: [PATCH] Add toast error for too many requests --- web/lib/api.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/web/lib/api.ts b/web/lib/api.ts index 0e287560..051ef622 100644 --- a/web/lib/api.ts +++ b/web/lib/api.ts @@ -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

( path: P, @@ -21,7 +22,12 @@ export async function api

( } } - 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

(path: P) {