From 89e8dc69caffffe4afe2459ed456933b50707d0e Mon Sep 17 00:00:00 2001 From: Dakshesh Jain Date: Wed, 26 Jul 2023 13:34:06 +0530 Subject: [PATCH] fix: displaying API error for AI response --- apps/app/components/core/modals/gpt-assistant-modal.tsx | 5 ++++- apps/app/components/issues/form.tsx | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/app/components/core/modals/gpt-assistant-modal.tsx b/apps/app/components/core/modals/gpt-assistant-modal.tsx index f1b24c65bd7..7c05e036a1d 100644 --- a/apps/app/components/core/modals/gpt-assistant-modal.tsx +++ b/apps/app/components/core/modals/gpt-assistant-modal.tsx @@ -117,18 +117,21 @@ export const GptAssistantModal: React.FC = ({ else setInvalidResponse(false); }) .catch((err) => { + const error = err?.data?.error; + if (err.status === 429) setToastAlert({ type: "error", title: "Error!", message: + error || "You have reached the maximum number of requests of 50 requests per month per user.", }); else setToastAlert({ type: "error", title: "Error!", - message: "Some error occurred. Please try again.", + message: error || "Some error occurred. Please try again.", }); }); }; diff --git a/apps/app/components/issues/form.tsx b/apps/app/components/issues/form.tsx index 1a87ac9fe21..e6fc11ae258 100644 --- a/apps/app/components/issues/form.tsx +++ b/apps/app/components/issues/form.tsx @@ -202,18 +202,21 @@ export const IssueForm: FC = ({ else handleAiAssistance(res.response_html); }) .catch((err) => { + const error = err?.data?.error; + if (err.status === 429) setToastAlert({ type: "error", title: "Error!", message: + error || "You have reached the maximum number of requests of 50 requests per month per user.", }); else setToastAlert({ type: "error", title: "Error!", - message: "Some error occurred. Please try again.", + message: error || "Some error occurred. Please try again.", }); }) .finally(() => setIAmFeelingLucky(false));