Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AIButton.tsx #375

Closed
wants to merge 1 commit into from

Conversation

aniruddhaadak80
Copy link

Purpose

This pull request addresses the error handling logic in the AI functionality of the document editor. It improves the handling of throttled requests and enhances the overall user experience.

Proposal

The proposal includes a refined error handling mechanism in the useHandleAIError function to manage throttled requests more effectively.

Changes Made:

  • Updated the error handling logic to use some() for better readability.
  • Implemented an early return for throttled requests to streamline the flow.
  • Ensured robust logging for debugging purposes.

Checklist

  • Improved error handling for throttled requests.
  • Maintained existing functionality without introducing breaking changes.

Code Changes

const useHandleAIError = () => {
  const { toast } = useToastProvider();
  const { t } = useTranslation();

  const handleAIError = useCallback(
    (error: unknown) => {
      if (isAPIError(error)) {
        const throttledMessage = 'Request was throttled. Expected available in 60 seconds.';
        
        const isThrottled = error.cause?.some(cause => cause === throttledMessage);

        if (isThrottled) {
          toast(t('Too many requests. Please wait 60 seconds.'), VariantType.ERROR);
          return; // Exit early if throttled
        }
      }

      toast(t('AI seems busy! Please try again.'), VariantType.ERROR);
      console.error(error);
    },
    [toast, t],
  );

  return handleAIError;
};

@AntoLC
Copy link
Collaborator

AntoLC commented Oct 23, 2024

Solved here #378.
Thank you.

@AntoLC AntoLC closed this Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants